Managed Memory

This is the Dragon managed memory interface for Python

Classes

class MemoryPoolAttr

Cython wrapper for managed memory attributes Currently unused

__init__(*args, **kwargs)
class MemoryAlloc

Cython wrapper object for memory pool allocations.

classmethod attach(ser_bytes)

Attach to a serialized memory allocation

Parameters

ser_bytes – Bytes-like object (memoryview, bytearray, bytes) of a serialized memory descriptor

Returns

MemoryAlloc object

clone(offset=0, length=None)

Clone this memory allocation with an offset into it.

Parameters

size – offset in bytes into this allocation

Returns

New MemoryAlloc object

Raises

RuntimeError

copy(pool: MemoryPool, timeout=None)

Copy an allocation into a pool

Parameters

pool – The pool in which to copy it.

Returns

A new memory allocation

Raises

DragonMemoryError

detach()

Detach from memory previously attached to.

free()

Free the managed memory allocation.

Returns

None

Raises

DragonMemoryError

get_memview()

Get a memoryview of the underlying memory

Returns

Memoryview object

pool

Return the pool of this memory allocation.

Returns

pool where this resides.

Raises

DragonMemoryError

serialize()

Serialize the memory allocation for storage or communication

Returns

Memoryview of the serialized data

size

Return the size of the allocation

return: the size in bytes of the memory allocation

class MemoryAllocations

Cython wrapper object to provide access to lists of existing memory allocations in a pool

alloc_type(idx)

Get the type of a particular allocation id.

Returns

Enum of the allocation type (if it exists)

Raises

RuntimeError if allocation not found

num_allocs

Number of allocations in pool.

class MemoryPool

Cython wrapper for managed memory pools and related structures

__init__()

Create a new memory pool and return a MemoryPool object.

Parameters
  • size – Size (in bytes) of the pool.

  • fname – Filename of the pool to use.

  • uid – Unique pool identifier to use.

  • mattr – MemoryPoolAttr object to specify various pool attributes. Currently Unused

Returns

MemoryPool object

Raises

DragonPoolCreateFail

alloc(size)

Allocate a memory block within this pool. Please note that the internal memory manager allocates to nearest powers of 2.

Parameters

size – Size (in bytes) to allocate

Returns

New MemoryAlloc object

Raises

RuntimeError

alloc_blocking(size, timeout=None)

Allocate a memory block within this pool. Please note that the internal memory manager allocates to nearest powers of 2.

Parameters

size – Size (in bytes) to allocate

Returns

New MemoryAlloc object

Raises

RuntimeError

allocation_exists(alloc_type, alloc_id)

Scan the pool to determine if a given allocation exists

Parameters
  • alloc_type – AllocType Enum of the allocation type

  • alloc_id – Integer ID of the allocation

Returns

True if allocation exists, False otherwise

classmethod attach(pool_ser, *, existing_memory_pool=None)

Attach to an existing pool through a serialized descriptor.

Parameters

pool_ser – Bytes-like object of a serialized pool descriptor.

Returns

MemoryPool object

Raises

DragonPoolAttachFail

destroy()

Destroy the pool created by this object.

detach(serialize=False)

Detach from a previously attached to pool by this object.

Parameters

serialize – Boolean to optionally store a serializer before detaching

get_alloc_by_id(alloc_type, alloc_id)

Get an allocation object by searching for type and ID

Parameters
  • alloc_type – AllocType Enum of the allocation type

  • alloc_id – Integer ID of the allocation

Returns

New MemoryAlloc object if allocation exists

Raises

RuntimeError if allocation does not exist

get_allocations()

Get a list of allocations in this pool

Returns

New MemoryAllocations object

serialize()

Serialize the pool held by this object. Will store a copy of the serialized data as part of the object after first call.

Returns

Memoryview of serialized pool descriptor.

Enums

class PoolType

TBD

class AllocType

TBD

Exceptions

exception DragonMemoryError

TBD

class Errors

An enumeration.

__init__(lib_err, msg)
exception DragonPoolError

TBD

class Errors

An enumeration.

exception DragonPoolCreateFail

TBD

exception DragonPoolAttachFail

TBD

exception DragonPoolDetachFail

TBD

exception DragonPoolAllocationNotAvailable

TBD