Max 5 API Reference
In the past, Max has provided two separate APIs for memory management. More...
Defines | |
#define | MM_UNIFIED |
This macro being defined means that getbytes and sysmem APIs for memory management are unified. | |
Functions | |
char * | getbytes (short size) |
Allocate small amounts of non-relocatable memory. | |
void | freebytes (void *b, short size) |
Free memory allocated with getbytes(). | |
char * | getbytes16 (short size) |
Use getbytes16() to allocate small amounts of non-relocatable memory that is aligned on a 16-byte boundary for use with vector optimization. | |
void | freebytes16 (char *mem, short size) |
Free memory allocated with getbytes16(). | |
char ** | newhandle (long size) |
Allocate relocatable memory. | |
short | growhandle (void *h, long size) |
Change the size of a handle. | |
void | disposhandle (char **h) |
Free the memory used by a handle you no longer need. | |
t_ptr | sysmem_newptr (long size) |
Allocate memory. | |
t_ptr | sysmem_newptrclear (long size) |
Allocate memory and set it to zero. | |
t_ptr | sysmem_resizeptr (void *ptr, long newsize) |
Resize an existing pointer. | |
t_ptr | sysmem_resizeptrclear (void *ptr, long newsize) |
Resize an existing pointer and clear it. | |
long | sysmem_ptrsize (void *ptr) |
Find the size of a pointer. | |
void | sysmem_freeptr (void *ptr) |
Free memory allocated with sysmem_newptr(). | |
void | sysmem_copyptr (const void *src, void *dst, long bytes) |
Copy memory the contents of one pointer to another pointer. | |
t_handle | sysmem_newhandle (long size) |
Allocate a handle (a pointer to a pointer). | |
t_handle | sysmem_newhandleclear (unsigned long size) |
Allocate a handle (a pointer to a pointer) whose memory is set to zero. | |
long | sysmem_resizehandle (t_handle handle, long newsize) |
Resize an existing handle. | |
long | sysmem_handlesize (t_handle handle) |
Find the size of a handle. | |
void | sysmem_freehandle (t_handle handle) |
Free memory allocated with sysmem_newhandle(). | |
long | sysmem_lockhandle (t_handle handle, long lock) |
Set the locked/unlocked state of a handle. | |
long | sysmem_ptrandhand (void *p, t_handle h, long size) |
Add memory to an existing handle and copy memory to the resized portion from a pointer. | |
long | sysmem_ptrbeforehand (void *p, t_handle h, unsigned long size) |
Add memory to an existing handle and copy memory to the resized portion from a pointer. | |
long | sysmem_nullterminatehandle (t_handle h) |
Add a null terminator to a handle. |
In the past, Max has provided two separate APIs for memory management.
One for allocating memory on the stack so that it was interrupt safe, including the getbytes() and freebytes() functions. The other, the "sysmem" API, were for allocating memory on the heap where larger amounts of memory were needed and the code could be guaranteed to operate at non-interrupt level.
Many things have changed in the environment of recent operating systems (MacOS X and Windows XP/Vista), the memory routines function differently, and the scheduler is no longer directly triggered by a hardware interrupt. In Max 5, the sysmem and getbytes API's have been unified, and thus may be used interchangeably.
The memory management unification can be switched on and off in the header files if needed, to compile code for older versions of Max for example, by changing the use of MM_UNIFIED in the Max headers.
The Sysmem API provides a number of utilities for allocating and managing memory. It is relatively similar to some of the Macintosh Memory Manager API, and not too different from Standard C library memory functions. It is not safe to mix these routines with other memory routines (e.g. don’t use malloc() to allocate a pointer, and sysmem_freeptr() to free it).
#define MM_UNIFIED |
void disposhandle | ( | char ** | h | ) |
Free the memory used by a handle you no longer need.
h | The handle to dispose. |
void freebytes | ( | void * | b, | |
short | size | |||
) |
Free memory allocated with getbytes().
As of Max 5 it is unified with sysmem_newptr(), which is the preferred method for allocating memory.
b | A pointer to the block of memory previously allocated that you want to free. | |
size | The size the block specified (as parameter b) in bytes. |
Referenced by jit_linklist_chuckindex(), jit_object_exportattrs(), jit_object_importattrs(), jit_qt_codec_getcodeclist_audio(), jit_qt_codec_getcodeclist_gfx(), jit_qt_codec_getcodeclist_video(), max_jit_attr_getdump(), max_jit_obex_gimmeback(), and max_jit_obex_gimmeback_dumpout().
void freebytes16 | ( | char * | mem, | |
short | size | |||
) |
Free memory allocated with getbytes16().
As of Max 5 it is unified with sysmem_newptr(), which is the preferred method for allocating memory.
mem | A pointer to the block of memory previously allocated that you want to free. | |
size | The size the block specified (as parameter b) in bytes. |
char* getbytes | ( | short | size | ) |
Allocate small amounts of non-relocatable memory.
As of Max 5 it is unified with sysmem_newptr(), which is the preferred method for allocating memory.
size | The size to allocate in bytes (up to 32767 bytes). |
char* getbytes16 | ( | short | size | ) |
Use getbytes16() to allocate small amounts of non-relocatable memory that is aligned on a 16-byte boundary for use with vector optimization.
size | The size to allocate in bytes (up to 32767 bytes). |
short growhandle | ( | void * | h, | |
long | size | |||
) |
Change the size of a handle.
h | The handle to resize. | |
size | The new size to allocate in bytes. |
char** newhandle | ( | long | size | ) |
Allocate relocatable memory.
size | The size to allocate in bytes. |
void sysmem_copyptr | ( | const void * | src, | |
void * | dst, | |||
long | bytes | |||
) |
Copy memory the contents of one pointer to another pointer.
This function is similar to BlockMove() or memcpy(). It copies the contents of the memory from the source to the destination pointer.
src | A pointer to the memory whose bytes will be copied. | |
dst | A pointer to the memory where the data will be copied. | |
bytes | The size in bytes of the data to be copied. |
void sysmem_freehandle | ( | t_handle | handle | ) |
Free memory allocated with sysmem_newhandle().
handle | The handle whose memory will be freed. |
Referenced by jit_handle_free().
void sysmem_freeptr | ( | void * | ptr | ) |
Free memory allocated with sysmem_newptr().
This function is similar to DisposePtr or free. It frees the memory that had been allocated to the given pointer.
ptr | The pointer whose memory will be freed. |
Referenced by jit_disposeptr(), jit_freebytes(), and jit_qt_utils_tempfile().
long sysmem_handlesize | ( | t_handle | handle | ) |
Find the size of a handle.
This function is similar to GetHandleSize().
handle | The handle whose size will be queried. |
Referenced by jit_handle_size_get().
long sysmem_lockhandle | ( | t_handle | handle, | |
long | lock | |||
) |
Set the locked/unlocked state of a handle.
This function is similar to HLock or HUnlock. It sets the lock state of a handle, using a zero or non-zero number.
handle | The handle that will be locked. | |
lock | The new lock state of the handle. |
Referenced by jit_handle_lock().
t_handle sysmem_newhandle | ( | long | size | ) |
Allocate a handle (a pointer to a pointer).
This function is similar to NewHandle(). It allocates a handle of a given number of bytes and returns a t_handle.
size | The size of the handle in bytes that will be allocated. |
Referenced by jit_handle_new().
t_handle sysmem_newhandleclear | ( | unsigned long | size | ) |
Allocate a handle (a pointer to a pointer) whose memory is set to zero.
size | The size of the handle in bytes that will be allocated. |
t_ptr sysmem_newptr | ( | long | size | ) |
Allocate memory.
This function is similar to NewPtr() or malloc(). It allocates a pointer of a given number of bytes and returns a pointer to the memory allocated.
size | The amount of memory to allocate. |
Referenced by jit_getbytes(), and jit_newptr().
t_ptr sysmem_newptrclear | ( | long | size | ) |
Allocate memory and set it to zero.
This function is similar to NewPtrClear() or calloc(). It allocates a pointer of a given number of bytes, zeroing all memory, and returns a pointer to the memory allocated.
size | The amount of memory to allocate. |
long sysmem_nullterminatehandle | ( | t_handle | h | ) |
Add a null terminator to a handle.
h | A handle to null terminate. |
long sysmem_ptrandhand | ( | void * | p, | |
t_handle | h, | |||
long | size | |||
) |
Add memory to an existing handle and copy memory to the resized portion from a pointer.
This function is similar to PtrAndHand(). It resizes an existing handle by adding a given number of bytes to it and copies data from a pointer into those bytes.
p | The existing pointer whose data will be copied into the resized handle. | |
h | The handle which will be enlarged by the size of the pointer. | |
size | The size in bytes that will be added to the handle. |
long sysmem_ptrbeforehand | ( | void * | p, | |
t_handle | h, | |||
unsigned long | size | |||
) |
Add memory to an existing handle and copy memory to the resized portion from a pointer.
Unlike sysmem_ptrandhand(), however, this copies the ptr before the previously exising handle data.
p | The existing pointer whose data will be copied into the resized handle. | |
h | The handle which will be enlarged by the size of the pointer. | |
size | The size in bytes that will be added to the handle. |
long sysmem_ptrsize | ( | void * | ptr | ) |
Find the size of a pointer.
This function is similar to _msize().
ptr | The pointer whose size will be queried |
long sysmem_resizehandle | ( | t_handle | handle, | |
long | newsize | |||
) |
Resize an existing handle.
This function is similar to SetHandleSize(). It resizes an existing handle to the size specified.
handle | The handle that will be resized. | |
newsize | The new size of the handle in bytes. |
Referenced by jit_handle_size_set().
t_ptr sysmem_resizeptr | ( | void * | ptr, | |
long | newsize | |||
) |
Resize an existing pointer.
This function is similar to realloc(). It resizes an existing pointer and returns a new pointer to the resized memory.
ptr | The pointer to the memory that will be resized. | |
newsize | The new size of the pointer in bytes. |
t_ptr sysmem_resizeptrclear | ( | void * | ptr, | |
long | newsize | |||
) |
Resize an existing pointer and clear it.
ptr | The pointer to the memory that will be resized. | |
newsize | The new size of the pointer in bytes. |