# vceCreateMemory

Allocates a memory block and assigns a voice handle to it.

#### Prototype

DWORD vceCreateMemory ( CTAHD ctahd, unsigned bytes, unsigned encoding, VCEHD *vh)

Argument | Description
ctahd | Handle returned by ctaCreateContext or ctaAttachContext.
bytes | Size of the memory block, in bytes.
encoding | Type of voice encoding of all data in the memory block.
vh | Pointer to a returned voice handle.

#### Return values

Return value | Description
SUCCESS |
CTAERR_INVALID_CTAHD | Context handle is invalid.
CTAERR_OUT_OF_MEMORY | Unable to allocate memory.
CTAERR_SVR_COMM | Server communication error.
VCEERR_UNSUPPORTED_ENCODING | Neither the Voice Message service or the associated play or record service, if any, support the specified encoding.

#### Details

vceCreateMemory allocates a range of memory and assigns a voice handle to it. The size is specified in bytes.

An open memory object initially has only one non-empty message, which is assigned message zero (0). The size of this message is equal to the size of the memory block. To record to a message other than message zero (0), either erase message zero (0) or resize it by recording or writing a message that is smaller than the entire memory block.

If your memory block contains multiple messages, use vceDefineMessages to tell the Voice Message service how the memory is partitioned.

Memory is always opened in PLAY_RECORD mode. There is no protection against opening overlapping memory regions. There is no interlock to prevent multiple threads recording to the same area from different contexts.

Unlike voice files, memory objects cannot grow.

Note: Recording to a memory object ends with CTA_REASON_FINISHED if the message is bounded by the next message or if the end of the memory block is reached.

Use vceClose to free memory and release the handle and internal resources.

Use vceRead to access data within the memory block.

Launch vceCreateMemory when using either the inproc default server or the localhost default server.

#### See also

vceOpenMemory

#### Example

/* myCreateMemory - Allocate a block of memory and get a voice handle to it. */
void myCreateMemory (CTAHD ctahd, unsigned maxtime, unsigned encoding,
VCEHD *vh)
{
unsigned framesize;
unsigned frametime;
unsigned bytes;
unsigned ret;
vceGetEncodingInfo (ctahd, encoding, &framesize, &frametime);
bytes = maxtime/frametime * framesize;
ret = vceCreateMemory (ctahd, bytes, encoding, vh);
if (ret != SUCCESS)
{
char textbuf[80];
ctaGetText (ctahd, ret, textbuf, sizeof(textbuf));
printf("Error creating memory: error %s from vceCreateMemory\n",
textbuf);
}
}