Max 5 API Reference
00001 /** 00002 @page chapter_memory Memory Allocation 00003 00004 The Max API offers cross-platform calls memory management. There are two types of calls, those for pointers and those for handles. Handles are pointers to pointers, and were used in the early Mac OS to permit memory to be relocated without changing a reference, and many Mac OS API calls used handle. There are a few legacy Max API calls that use handles as well, but in general, unless the OS or Max requires the use of a handle, you're probably better off using the simpler pointer. 00005 00006 Longtime Max object programmers may have used memory calls getbytes() and freebytes() in the past, but all memory calls now use same underlying OS mechanisms, so while getbytes() and freebytes() are still supported, they are restricted to 32K of memory or less due to the arguments they use, and we recommend the use of sysmem_newptr() and sysmem_freeptr() instead. 00007 00008 00009 Here are some examples of allocating and freeing pointers and handles. 00010 00011 @code 00012 char *ptr; 00013 char **hand; 00014 00015 ptr = sysmem_newptr(2000); 00016 post("I have a pointer %lx and it is %ld bytes in size",ptr, sysmem_ptrsize(ptr)); 00017 ptr = sysmem_resizeptrclear(ptr, 3000); 00018 post("Now I have a pointer %lx and it is %ld bytes in size",ptr, sysmem_ptrsize(ptr)); 00019 sysmem_freeptr(ptr); 00020 00021 hand = sysmem_newhandle(2000); 00022 post("I have a handle %lx and it is %ld bytes in size",hand, sysmem_handlesize(hand)); 00023 sysmem_resizehandle(hand, 3000); 00024 post("Now the handle %lx is %ld bytes in size",hand, sysmem_ptrsize(hand)); 00025 sysmem_freehandle(hand); 00026 @endcode 00027 00028 00029 */
Copyright © 2008, Cycling '74