Scaleform::SysAllocBase Scaleform::SysAllocPaged
class SysAllocPaged : public SysAllocBase;
SysAllocPaged is an abstract interface used to provide allocations to page based MemoryHeapPT memory system, first introduced with GFx 3.0. Unlike SysAlloc, this system requires 4K page alignment on allocations and will in general keep larger blocks allocated. This system is best for OS-direct allocations, being able to take advantage of HW paging, and is also used to implement SysAllocStatic. Note, if you plan to implement interface by delegating to malloc/dlmalloc based API, SysAlloc is a better choice.
Users can implement SysAllocPaged to delegate allocations to their own memory allocator. Developers implementing this interface need to define at least three functions: GetInfo, Alloc and Free. When running, GFx will allocate and free large blocks through this interface, managing all of the smaller allocations internally. As GFx uses 4K alignment for large blocks internally, it is best if this interface maps directly to OS implementation. When this is not the case, it is best to use 64K+ granularity to make sure that minimal memory is not wasted on alignment.
Scaleform provides several default SysAllocPaged implementations:
1. Memory Range Based : SysAllocPagedStatic, which accepts a memory range in constructor, forcing GFx to work within a block of memory.
2. System Specific : SysAllocPagedWin32, etc, which uses OS specific implementation such as VirtualAlloc, mmap, etc to allocate memory pages. This implementation is most efficient for the target platform. This heap is used by default in GFx::System if you don't specify a different allocator.
3. Malloc version: SysAllocPagedMalloc, which uses standard library functions such as memalign() and free(). The source code to these implementations can be used as reference for user implementation. It is better to use SysAlloc derived implementation instead of SysAllocPagedMalloc.
Users can implement their own system allocators by
1. Creating their own implementation of SysAllocPaged interface and modifying it to make calls to their own memory allocator or heap. A simple way to implement user memory heap is to copy the SysAllocPagedMalloc implementation and modify it to make calls to your memory allocator. Slightly modified SysAllocPagedMalloc allocator code is included below for reference:
class MySysAlloc : public Scaleform::SysAllocPaged { public: virtual void GetInfo(Info* i) const { i->MinAlign = 1; i->MaxAlign = 1; i->Granularity = 128*1024; i->HasRealloc = false; } virtual void* Alloc(UPInt size, UPInt align) { return malloc(size); } virtual bool Free(void* ptr, UPInt size, UPInt align) { free(ptr); return true; } };
2. Providing an instance of this allocator in GFx::System constructor during GFx initialization.
MySysAlloc myAlloc; Scaleform::GFx::System gfxSystem(&myAlloc);
Method |
Description |
Allocates a large block of memory to the heap. | |
Frees the block of memory allocated by Alloc. | |
Returns the number of bytes allocated from the system for the system allocator. | |
Returns the allocator alignment support and granularity capabilities of the system allocator implementation by filling in the information structure, Info. | |
Returns the actual amount of allocated/used bytes in the heap. | |
Attempts to reallocate memory to a new size without moving it. | |
SysAllocPaged constructor. |
Structure |
Description |
Structure providing information on the capabilities such as alignment and granularity of SysAllocPaged implementation. |
SF_SysAlloc.h