Memory management classes

ImebraMemoryPool

class ImebraMemoryPool : public NSObject

Public Static Functions

void flush()

Release all the unused memory regions.

unsigned int getUnusedMemorySize()

Return the total size of the memory that has been released but not yet freed.

Return
the total size of the memory released but not yet freed

void ImebraMemoryPool::setMemoryPoolSize:maxSize:(unsigned int minMemoryBlockSize, unsigned int maxMemoryPoolSize)

Set the maximum size of the kept unused memory.

Parameters
  • minMemoryBlockSize: if a memory region is smaller than this size then when it is released it is deleted immediately, otherwise it is kept in the memory pool
  • maxMemoryPoolSize: the maximum size of the sum of all the unused memory regions. When the total size of the unused memory regions is greater than this parameter then the oldest memory regions are deleted permanently

ImebraReadMemory

class ImebraReadMemory : public NSObject

Manages a read-only buffer of memory.

The buffer of memory is usually associated with a ImebraTag buffer content.

The memory used by ImebraReadMemory and ImebraReadWriteMemory is managed by ImebraMemoryPool.

Subclassed by ImebraReadWriteMemory

Public Functions

id ImebraReadMemory::initWithData:(NSData * source)

Construct a buffer of memory and copy the specified content into it.

Parameters
  • source: a pointer to the source data

NSData *data()

Copies the raw memory content into a NSData object and returns it.

Return
a NSData containing a copy of the memory managed by ImebraReadMemory

Property

property ImebraReadMemory::empty

Return true if the referenced memory is zero bytes long or hasn’t been allocated yet.

ImebraReadWriteMemory

class ImebraReadWriteMemory : public ImebraReadMemory

Manages a writable buffer of memory.

The buffer of memory is usually associated with a tag buffer content.

The memory used by ImebraReadMemory and ImebraReadWriteMemory is managed by ImebraMemoryPool.

Public Functions

id init()

Construct an empty buffer of memory.

The memory can be resized later with resize().

id ImebraReadWriteMemory::initWithSize:(unsigned int size)

Construct a buffer of memory of the specified size.

The memory can be resized later with resize().

Parameters
  • size: the initial memory’s size, in bytes

id ImebraReadWriteMemory::initWithMemory:(ImebraReadMemory * source)

Construct a buffer of memory and copy the specified content into it.

Parameters
  • source: the object containing the initial memory’s content

id ImebraReadWriteMemory::initWithData:(NSData * pSource)

Construct a buffer of memory and copy the specified content into it.

Parameters
  • pSource: the object containing the initial memory’s content

void ImebraReadWriteMemory::copyFrom:error:(ImebraReadMemory * source, (swift_error(nonnull_error)) __attribute__)

Copy the content from another memory object.

Parameters
  • source: the source memory object
  • pError: set to a NSError derived class in case of error

void ImebraReadWriteMemory::clear:((swift_error(nonnull_error)) __attribute__)

Resize the memory to zero bytes.

Parameters
  • pError: set to a NSError derived class in case of error

void ImebraReadWriteMemory::resize:error:(unsigned int newSize, (swift_error(nonnull_error)) __attribute__)

Resize the memory.

Parameters
  • newSize: the new memory size, in bytes
  • pError: set to a NSError derived class in case of error

void reserve(size_t reserveSize)

Reserve the specified amount of bytes, without changing the memory size.

Parameters
  • reserveSize: the number of bytes to reserve
  • pError: set to a NSError derived class in case of error

void ImebraReadWriteMemory::assign:error:(NSData * pSource, (swift_error(nonnull_error)) __attribute__)

Copy the content of the specified buffer into the ReadWriteMemory object.

Parameters
  • pSource: a pointer to the source memory buffer
  • pError: set to a NSError derived class in case of error

void ImebraReadWriteMemory::assignRegion:offset:error:(NSData * pSource, unsigned int destinationOffset, (swift_error(nonnull_error)) __attribute__)

Copy the content of the specified buffer into a region of the ReadWriteMemory.

The memory size remains unchanged.

Parameters
  • pSource: a pointer to the source memory buffer
  • destinationOffset: the offset into the ReadWriteMemory at which the data must be copied
  • pError: set to a NSError derived class in case of error