Skip to content

TSdlMemoryManager

To customize SDL's memory manager

Definition

Unit: Neslib.Sdl3.Additional

type TSdlMemoryManager = record ... end;

Fields

Name Description
CAlloc The callback used to implement SdlCAlloc.
Free The callback used to implement SdlFree.
MAlloc The callback used to implement SdlMAlloc.
Realloc The callback used to implement SdlRealloc.

Properties

Name Description
Current The current set of SDL memory functions.
Original The original set of SDL memory functions.

Methods

Name Description
UseDelphis Sets the memory functions to use Delphi's built-in functions (like GetMem and FreeMem) instead.

Field Descriptions

CAlloc

The callback used to implement SdlCAlloc.

var CAlloc: TSdlCAllocFunc

Type: TSdlCAllocFunc


Free

The callback used to implement SdlFree.

var Free: TSdlFreeFunc

Type: TSdlFreeFunc


MAlloc

The callback used to implement SdlMAlloc.

var MAlloc: TSdlMAllocFunc

Type: TSdlMAllocFunc


Realloc

The callback used to implement SdlRealloc.

var Realloc: TSdlReallocFunc

Type: TSdlReallocFunc


Property Descriptions

Current

The current set of SDL memory functions.

It is not safe to change the memory functions once any allocations have been made, as future calls to SdlFree will use the new allocator, even if they came from an SdlMAlloc made with the old one!

If set, usually this needs to be the first call made into the SDL library, if not the very first thing done at program startup time.

class property Current: TSdlMemoryManager read GetCurrent write SetCurrent

Type: TSdlMemoryManager

Exceptions

ESdlError: Raised on failure.

See Also

Remarks

This does not hold a lock, so do not use this in the unlikely event of a background thread setting this simultaneously.


Original

The original set of SDL memory functions.

This is what SdlMAlloc and friends will use by default, if no custom memory manager has been set (using Current). This is not necessarily using the C runtime's malloc functions behind the scenes! Different platforms and build configurations might do any number of unexpected things.

class property Original: TSdlMemoryManager read GetOriginal

Type: TSdlMemoryManager

See Also

Remarks

It is safe to use this property from any thread


Method Descriptions

UseDelphis

Sets the memory functions to use Delphi's built-in functions (like GetMem and FreeMem) instead.

This enables you to use a single set of memory management functions, as well as enable features like ReportMemoryLeaksOnShutdown.

It is not safe to change the memory functions once any allocations have been made, as future calls to SdlFree will use the new allocator, even if they came from an SdlMAlloc made with the old one!

Uusually this needs to be the first call made into the SDL library, if not the very first thing done at program startup time.

class procedure UseDelphis; static

Exceptions

ESdlError: Raised on failure.

See Also

Remarks

This does not hold a lock, so do not use this in the unlikely event of a background thread setting this simultaneously.