[Enterprise Extensions only]

CORBA::string_alloc

Overview Allocates storage for a string.
Original class CORBA


Intended Usage

This method is intended to be used by client and server applications to dynamically allocate storage for data of type CORBA::String. The returned storage should subsequently be freed using CORBA::string_free(). Strings can also be copied using CORBA::string_dup().

Strings to be passed on remote method invocations or whose ownership is to be transferred by one library to another should be allocated using CORBA::string_alloc() (or CORBA::string_dup()) rather than the C++ new[] operator. This insures that string memory is deleted using the same C++ run time that originally allocated it.

IDL Syntax

  static char* string_alloc(CORBA::ULong len);

Input parameters

len
The size of the string whose storage is to be allocated. An additional byte is also allocated for the terminating NULL character.

Return values

char*
The uninitialized string storage. This storage should later be freed using CORBA::string_free(). NULL is returned if the storage cannot be allocated.

Example

  /* The following is a C++ example */
  #include "corba.h"
  ...
  /* Allocate 8 byes for string buf */
  char* buf = CORBA::string_alloc(8);
  /* String copy buf */
  char* buf_dup = CORBA::string_dup(buf);
  /* Use buf and buf_dup */
  ...
  /* free buf and buf_dup */
  CORBA::string_free(buf);
  CORBA::string_free(buf_dup);