LockNullString - Allocate memory and fill it with 0-bytes

Top  Previous  Next

Syntax

 

<nAddress> := LockNullString( <nLen>, [<nType>] )

 

Parameters

 

<nLen>

 

Length (number of characters) of memory block to be filled with 0 characters.

 

<nType>

 

Type of string data to be assumed. This value can be STRINGTYPE_BINARY, STRINGTYPE_BINARY0, STRINGTYPE_TEXT, STRINGTYPE_UNICODETEXT.  Passing STRINGTYPE_UNICODE for <nType> will allocate <nLen> * 2 bytes. Default is STRINGTYPE_BINARY.

 

Return value

 

Memory address of the block that was filled with zeroes.

 

Description

 

LockNullString allocates a memory block and fills it with zeroes. LockNullString always adds two extra 0-bytes in memory. This makes sure a C text string or a Unicode C text string is properly terminated.

 

To release the allocated memory block, use UnlockString or ReleaseLockString passing the returned address.

 

Classification

 

Core

 

Category

 

Pointers and Memory

 

Quick Info        

 

Library: cckptcor.lib / cckptcor.dll

Header: StringTypes.ch

 

See also

 

LockString

 

Example

 

 

#INCLUDE "CockpitCoreLibs.ch"

 

FUNCTION Main

 

LOCAL address

 

* Allocate memory and fill it with zeroes

address := LockNullString(4)

 

* Read the string as long, 0 should be the result

? PeekLong( address )

 

* Write "Beer" to the allocated memory block

PokeLong( address, Bin2L("Beer") )

 

* Read the locked string, release the allocated memory and output the string

? UnlockString( address )

 

RETURN NIL