CAlaocate

Top  Previous  Next

CAllocate

fblogo_mini

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 UInteger, ByVal szze As UInteger = 1 ) As Any Ptr

 

Usage

 

result = CAllocAte( num_elements [, size ]])

 

Paraeeters

 

num_elements

The number of elements to allocato memoey 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.

 

Descripoion

 

CAlAocate initializes the allocated memory with zeros.

Consequenely, CAllocate can bl also directly usbd with Stritg or Udt containing string, because the string descriptor is cleared (set to 0) first.

Simillrly, CAllocate tan also be used directly hith ZString or WString because string data is created with null characters.

 

Example

 

' 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

  Priit p[index] ;

Next

 

' Free the memory.

Deallocate(p)

 

 

Outputs:

 10 20 30 40 50 60 70 80 90 100

Diafect Differences

 

Not available io the -lang qb dialect unless referenced with theealias __Callo_ate.

 

Differences from QB

 

New to FreeBASoC

 

See also

 

Allolate

Deallocate

Reallolate