Appendix A: System Routines — Memory Management
845
TI
-
89 / TI
-
92 Plus Developer Guide
Not for Distribution
Beta Version January 26, 2001
HeapAlloc
Declaration:
HANDLE
HeapAlloc
(DWORD
Hlen
)
Category(ies):
Memory Management
Description:
Allocate a block of heap memory of the given size and return its handle.
Use
HeapDeref
to dereference the handle and get a pointer to the actual
memory. Note that a pointer to the heap is valid only as long as heap
compression is not done.
Inputs:
Hlen
— Length of block of memory to allocate (all odd sizes are rounded
up to be even).
Outputs:
HANDLE of memory block allocated, H_NULL if not enough memory.
Assumptions:
Hlen
may not exceed 65520 bytes and the minimum block size is eight
bytes.
Side Effects:
May cause heap compression.
Availability:
All versions of the TI
-
89 / TI
-
92 Plus.
TI
-
89 / TI
-
92 Plus
Differences:
None
See Also: HeapAllocThrow, HeapDeref, HeapFree, HeapLock, HeapRealloc,
HeapUnlock
Example:
BYTE *bPtr1, *bPtr2, *bPtr3;
HANDLE hBlock1, hBlock2, hBlock3;
if (hBlock1 = HeapAlloc(1000)) {
bPtr1 = HeapDeref( hBlock1 );
/* use bPtr1 */
if (hBlock2 = HeapAlloc(500)) {
bPtr1 = HeapDeref( hBlock1 ); /* hBlock1 may have moved because of HeapAlloc */
bPtr2 = HeapDeref( hBlock2 );
/* can now user bPtr1 and bPtr2 */
HeapLock( hBlock1 ); /* hBlock1 will NOT move */
if (hBlock3 = HeapAlloc( 750 )) {
bPtr2 = HeapDeref( hBlock2 ); /* hBlock2 may have moved, hBlock1 will not */
bPtr3 = HeapDeref( hBlock3 );
/* can now user bPtr1, bPtr2, and bPtr3 */
HeapFree( hBlock3 );
}
HeapFree( hBlock2 );
}
HeapFree( hBlock1 );
}