github.com/256dpi/max-go@v0.7.0/lib/max/ext_sysmem.h (about)

     1  
     2  #ifndef _EXT_SYSMEM_H_
     3  #define _EXT_SYSMEM_H_
     4  
     5  #include "ext_prefix.h"
     6  #include "max_types.h"
     7  
     8  BEGIN_USING_C_LINKAGE
     9  
    10  #ifndef sysmem_newptr
    11  /**
    12  	Allocate memory.
    13  	This function is similar to NewPtr() or malloc(). It allocates a pointer of 
    14  	a given number of bytes and returns a pointer to the memory allocated.
    15  		
    16  	@ingroup memory
    17  	@param	size	The amount of memory to allocate.
    18  	@return			A pointer to the allocated memory, or NULL if the allocation fails.
    19  */
    20  t_ptr sysmem_newptr(t_ptr_size size);
    21  
    22  #endif
    23  
    24  
    25  /**
    26  	Allocate memory and set it to zero.
    27  	This function is similar to NewPtrClear() or calloc(). 	 
    28  	It allocates a pointer of a given number of bytes, zeroing all memory, 
    29  	and returns a pointer to the memory allocated.
    30  
    31  	@ingroup memory
    32  	@param	size	The amount of memory to allocate.
    33  	@return			A pointer to the allocated memory, or NULL if the allocation fails.
    34  */
    35  t_ptr sysmem_newptrclear(t_ptr_size size);
    36  
    37  
    38  /**
    39  	Resize an existing pointer. 
    40  	This function is similar to realloc(). 
    41  	It resizes an existing pointer and returns a new pointer to the resized memory.
    42  
    43  	@ingroup memory
    44  	@param	ptr		The pointer to the memory that will be resized.
    45  	@param	newsize	The new size of the pointer in bytes.
    46  	@return			A pointer to the resized memory, or NULL if the allocation fails.
    47  */
    48  t_ptr sysmem_resizeptr(void *ptr, t_ptr_size newsize);
    49  
    50  
    51  /**
    52  	Resize an existing pointer and clear the newly allocated memory, if any. 
    53  
    54  	@ingroup memory
    55  	@param	ptr		The pointer to the memory that will be resized.
    56  	@param	newsize	The new size of the pointer in bytes.
    57  	@return			A pointer to the resized memory, or NULL if the allocation fails.
    58  */
    59  t_ptr sysmem_resizeptrclear(void *ptr, t_ptr_size newsize);
    60  
    61  
    62  /**
    63  	Find the size of a pointer.  This function is similar to _msize().
    64  
    65  	@ingroup memory
    66  	@param	ptr		The pointer whose size will be queried
    67  	@return			The number of bytes allocated to the pointer specified.
    68  */
    69  t_ptr_size sysmem_ptrsize(void *ptr);
    70  
    71  
    72  /**
    73  	Free memory allocated with sysmem_newptr().
    74  	This function is similar to DisposePtr or free. 
    75  	It frees the memory that had been allocated to the given pointer.
    76  
    77  	@ingroup memory
    78  	@param	ptr		The pointer whose memory will be freed.
    79  */
    80  void sysmem_freeptr(void *ptr);
    81  
    82  #ifndef sysmem_copyptr
    83  /**
    84  	Copy memory the contents of one pointer to another pointer.
    85  	This function is similar to BlockMove() or memcpy(). 
    86  	It copies the contents of the memory from the source to the destination pointer.
    87  
    88  	@ingroup memory
    89  	@param	src		A pointer to the memory whose bytes will be copied.
    90  	@param	dst		A pointer to the memory where the data will be copied.
    91  	@param	bytes	The size in bytes of the data to be copied.
    92  */
    93  void sysmem_copyptr(const void *src, void *dst, t_ptr_size bytes);
    94  
    95  #endif
    96  
    97  
    98  /**
    99  	Allocate a handle (a pointer to a pointer).
   100  	This function is similar to NewHandle(). 
   101  	It allocates a handle of a given number of bytes and returns a #t_handle.
   102  
   103  	@ingroup memory
   104  	@param	size	The size of the handle in bytes that will be allocated. 
   105  	@return			A new #t_handle.
   106  */
   107  t_handle sysmem_newhandle(t_ptr_size size);
   108  
   109  
   110  /**
   111  	Allocate a handle (a pointer to a pointer) whose memory is set to zero.
   112  
   113  	@ingroup memory
   114  	@param	size	The size of the handle in bytes that will be allocated. 
   115  	@return			A new #t_handle.
   116  	@see			sysmem_newhandle()
   117  */
   118  t_handle sysmem_newhandleclear(t_ptr_size size);
   119  
   120  
   121  /**
   122  	Resize an existing handle.
   123  	This function is similar to SetHandleSize().
   124  	It resizes an existing handle to the size specified.
   125  
   126  	@ingroup memory
   127  	@param	handle	The handle that will be resized. 
   128  	@param	newsize	The new size of the handle in bytes. 
   129  	@return			The number of bytes allocated to the specified handle.
   130  */
   131  t_max_err sysmem_resizehandle(t_handle handle, t_ptr_size newsize);
   132  
   133  
   134  /**
   135  	Find the size of a handle. 
   136  	This function is similar to GetHandleSize(). 
   137  
   138  	@ingroup memory
   139  	@param	handle	The handle whose size will be queried.
   140  	@return			The number of bytes allocated to the specified handle.
   141  */
   142  t_ptr_size sysmem_handlesize(t_handle handle);
   143  
   144  
   145  /**
   146  	Free memory allocated with sysmem_newhandle().
   147  
   148  	@ingroup memory
   149  	@param	handle	The handle whose memory will be freed.
   150  */
   151  void sysmem_freehandle(t_handle handle);
   152  
   153  
   154  /**
   155  	Set the locked/unlocked state of a handle.
   156  	This function is similar to HLock or HUnlock. 
   157  	It sets the lock state of a handle, using a zero or non-zero number.
   158  		
   159  	@ingroup memory
   160  	@param	handle	The handle that will be locked. 
   161  	@param	lock	The new lock state of the handle. 
   162  	@return			The previous lock state.
   163  */
   164  int sysmem_lockhandle(t_handle handle, int lock);
   165  
   166  
   167  /**
   168  	Add memory to an existing handle and copy memory to the resized portion from a pointer.
   169  	This function is similar to PtrAndHand(). It resizes an existing handle 
   170  	by adding a given number of bytes to it and copies data from a pointer 
   171  	into those bytes.
   172  
   173  	@ingroup memory
   174  	@param	p		The existing pointer whose data will be copied into the resized handle.
   175  	@param	h		The handle which will be enlarged by the size of the pointer.
   176  	@param	size	The size in bytes that will be added to the handle.
   177  	@return			The number of bytes allocated to the specified handle.
   178  */
   179  t_max_err sysmem_ptrandhand(void *p, t_handle h, t_ptr_size size);
   180  
   181  
   182  /**	Add memory to an existing handle and copy memory to the resized portion from a pointer.
   183  	Unlike sysmem_ptrandhand(), however, this copies the ptr before the previously exising handle data.
   184  
   185  	@ingroup memory
   186  	@param	p		The existing pointer whose data will be copied into the resized handle.
   187  	@param	h		The handle which will be enlarged by the size of the pointer.
   188  	@param	size	The size in bytes that will be added to the handle.
   189  	@return			An error code.
   190  */
   191  t_max_err sysmem_ptrbeforehand(void *p, t_handle h, t_ptr_size size);
   192  
   193  
   194  /**	Add a null terminator to a handle.
   195  	@ingroup memory
   196  	@param	h		A handle to null terminate.
   197  	@return			An error code.
   198  */
   199  t_max_err sysmem_nullterminatehandle(t_handle h);
   200  
   201  
   202  END_USING_C_LINKAGE
   203  
   204  #endif // _EXT_SYSMEM_H_
   205