Max 5 API Reference
00001 00002 #ifndef _SYSMEM_H_ 00003 #define _SYSMEM_H_ 00004 00005 #ifdef __cplusplus 00006 extern "C" { 00007 #endif 00008 00009 00010 /** 00011 Allocate memory. 00012 This function is similar to NewPtr() or malloc(). It allocates a pointer of 00013 a given number of bytes and returns a pointer to the memory allocated. 00014 00015 @ingroup memory 00016 @param size The amount of memory to allocate. 00017 @return A pointer to the allocated memory, or NULL if the allocation fails. 00018 */ 00019 extern t_ptr sysmem_newptr(long size); 00020 00021 00022 /** 00023 Allocate memory and set it to zero. 00024 This function is similar to NewPtrClear() or calloc(). 00025 It allocates a pointer of a given number of bytes, zeroing all memory, 00026 and returns a pointer to the memory allocated. 00027 00028 @ingroup memory 00029 @param size The amount of memory to allocate. 00030 @return A pointer to the allocated memory, or NULL if the allocation fails. 00031 */ 00032 extern t_ptr sysmem_newptrclear(long size); 00033 00034 00035 /** 00036 Resize an existing pointer. 00037 This function is similar to realloc(). 00038 It resizes an existing pointer and returns a new pointer to the resized memory. 00039 00040 @ingroup memory 00041 @param ptr The pointer to the memory that will be resized. 00042 @param newsize The new size of the pointer in bytes. 00043 @return A pointer to the resized memory, or NULL if the allocation fails. 00044 */ 00045 extern t_ptr sysmem_resizeptr(void *ptr, long newsize); 00046 00047 00048 /** 00049 Resize an existing pointer and clear it. 00050 00051 @ingroup memory 00052 @param ptr The pointer to the memory that will be resized. 00053 @param newsize The new size of the pointer in bytes. 00054 @return A pointer to the resized memory, or NULL if the allocation fails. 00055 */ 00056 extern t_ptr sysmem_resizeptrclear(void *ptr, long newsize); 00057 00058 00059 /** 00060 Find the size of a pointer. This function is similar to _msize(). 00061 00062 @ingroup memory 00063 @param ptr The pointer whose size will be queried 00064 @return The number of bytes allocated to the pointer specified. 00065 */ 00066 extern long sysmem_ptrsize(void *ptr); 00067 00068 00069 /** 00070 Free memory allocated with sysmem_newptr(). 00071 This function is similar to DisposePtr or free. 00072 It frees the memory that had been allocated to the given pointer. 00073 00074 @ingroup memory 00075 @param ptr The pointer whose memory will be freed. 00076 */ 00077 extern void sysmem_freeptr(void *ptr); 00078 00079 00080 /** 00081 Copy memory the contents of one pointer to another pointer. 00082 This function is similar to BlockMove() or memcpy(). 00083 It copies the contents of the memory from the source to the destination pointer. 00084 00085 @ingroup memory 00086 @param src A pointer to the memory whose bytes will be copied. 00087 @param dst A pointer to the memory where the data will be copied. 00088 @param bytes The size in bytes of the data to be copied. 00089 */ 00090 extern void sysmem_copyptr(const void *src, void *dst, long bytes); 00091 00092 00093 /** 00094 Allocate a handle (a pointer to a pointer). 00095 This function is similar to NewHandle(). 00096 It allocates a handle of a given number of bytes and returns a #t_handle. 00097 00098 @ingroup memory 00099 @param size The size of the handle in bytes that will be allocated. 00100 @return A new #t_handle. 00101 */ 00102 extern t_handle sysmem_newhandle(long size); 00103 00104 00105 /** 00106 Allocate a handle (a pointer to a pointer) whose memory is set to zero. 00107 00108 @ingroup memory 00109 @param size The size of the handle in bytes that will be allocated. 00110 @return A new #t_handle. 00111 @see sysmem_newhandle() 00112 */ 00113 extern t_handle sysmem_newhandleclear(unsigned long size); 00114 00115 00116 /** 00117 Resize an existing handle. 00118 This function is similar to SetHandleSize(). 00119 It resizes an existing handle to the size specified. 00120 00121 @ingroup memory 00122 @param handle The handle that will be resized. 00123 @param newsize The new size of the handle in bytes. 00124 @return The number of bytes allocated to the specified handle. 00125 */ 00126 extern long sysmem_resizehandle(t_handle handle, long newsize); 00127 00128 00129 /** 00130 Find the size of a handle. 00131 This function is similar to GetHandleSize(). 00132 00133 @ingroup memory 00134 @param handle The handle whose size will be queried. 00135 @return The number of bytes allocated to the specified handle. 00136 */ 00137 extern long sysmem_handlesize(t_handle handle); 00138 00139 00140 /** 00141 Free memory allocated with sysmem_newhandle(). 00142 00143 @ingroup memory 00144 @param handle The handle whose memory will be freed. 00145 */ 00146 extern void sysmem_freehandle(t_handle handle); 00147 00148 00149 /** 00150 Set the locked/unlocked state of a handle. 00151 This function is similar to HLock or HUnlock. 00152 It sets the lock state of a handle, using a zero or non-zero number. 00153 00154 @ingroup memory 00155 @param handle The handle that will be locked. 00156 @param lock The new lock state of the handle. 00157 @return The previous lock state. 00158 */ 00159 extern long sysmem_lockhandle(t_handle handle, long lock); 00160 00161 00162 /** 00163 Add memory to an existing handle and copy memory to the resized portion from a pointer. 00164 This function is similar to PtrAndHand(). It resizes an existing handle 00165 by adding a given number of bytes to it and copies data from a pointer 00166 into those bytes. 00167 00168 @ingroup memory 00169 @param p The existing pointer whose data will be copied into the resized handle. 00170 @param h The handle which will be enlarged by the size of the pointer. 00171 @param size The size in bytes that will be added to the handle. 00172 @return The number of bytes allocated to the specified handle. 00173 */ 00174 extern long sysmem_ptrandhand(void *p, t_handle h, long size); 00175 00176 00177 /** Add memory to an existing handle and copy memory to the resized portion from a pointer. 00178 Unlike sysmem_ptrandhand(), however, this copies the ptr before the previously exising handle data. 00179 00180 @ingroup memory 00181 @param p The existing pointer whose data will be copied into the resized handle. 00182 @param h The handle which will be enlarged by the size of the pointer. 00183 @param size The size in bytes that will be added to the handle. 00184 @return An error code. 00185 */ 00186 extern long sysmem_ptrbeforehand(void *p, t_handle h, unsigned long size); 00187 00188 00189 /** Add a null terminator to a handle. 00190 @ingroup memory 00191 @param h A handle to null terminate. 00192 @return An error code. 00193 */ 00194 extern long sysmem_nullterminatehandle(t_handle h); 00195 00196 00197 #ifdef __cplusplus 00198 } 00199 #endif 00200 00201 #endif // _SYSMEM_H_ 00202
Copyright © 2008, Cycling '74