AllocMem
Allocates a block of native memory and returns its address.
Syntax: AllocMem( BytesToAlloc ) As LongPtr
- BytesToAlloc
- required Long. The size of the block to allocate, in bytes.
The contents of the new block are unspecified. Release the block with FreeMem when no longer needed; passing the address to anything else (e.g. a Win32 HeapFree) will not work, since the block is owned by the twinBASIC runtime’s heap.
Common Errors
| Error | When |
|---|---|
-2147024882 (&H8007000E), Not enough memory resources are available to complete this operation. | BytesToAlloc is 0 or less in a 32-bit build, there is not enough memory for the block (2,000,000,000 bytes, for one) |
94 (&H5E), Invalid use of Null | BytesToAlloc is Null |
Example
Dim Buffer As LongPtr = AllocMem(1024)
PutMem4 Buffer, &HDEADBEEF
'... use Buffer ...
FreeMem Buffer
See Also
- FreeMem procedure
- vbaCopyBytes function