FBWiki : KeyPgCallocate

FBWiki :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

CALLOCATE


Allocates memory for a certain number of elements from the free store and clears the contents

Syntax:
declare function Callocate cdecl ( byval num_elements as integer, byval size as integer = 1 ) as any ptr

Usage:
result = Callocate( bytes [, size ] )

Parameters:
num_elements
The number of elements to allocate memory for.
size
The size, in bytes, of each element.

Return Value:
If successful, the address of the start of the allocated memory is returned. Otherwise, the null pointer (0) is returned.

Description:
Callocate initializes the allocated memory with zeros.

Examples:
' Allocate and initialize space for 10 integer elements.
Dim p As Integer Ptr = CAllocate(10, SizeOf(Integer))

' Fill the memory with integer values.
For index As Integer = 0 To 9
    p[index] = (index + 1) * 10
Next

' Display the integer values.
For index As Integer = 0 To 9
    Print p[index] ;
Next

' Free the memory.
Deallocate(p)

Outputs:
 10 20 30 40 50 60 70 80 90 100


Platform Differences:

Dialect Differences:

Differences from QB:

See also:

Back to Memory Functions

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.0



sf.net phatcode