rwlogo

Rogue Wave Views
Foundation Package API Reference Guide

Product Documentation:

Rogue Wave Views
Documentation Home

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Functions
memory.h File Reference
#include <ilog/macros.h>
#include <stddef.h>
#include <string.h>

Macros

#define IL_MALLOC(type, n)
 Allocates an array of objects. More...
 
#define IL_REALLOC(type, array, n)
 Re-allocates an array of objects. More...
 
#define IL_STRCASECMP(s1, s2)
 Compares two strings in a case-insensitive manner. More...
 
#define IL_STRNCASECMP(s1, s2, n)
 Compares two strings in a case-insensitive manner. More...
 

Functions

char * IlCopyString (const char *string, IlBoolean zeroIfEmpty=IlTrue)
 Allocates and returns a copy of a string. More...
 
void IlFree (void *block)
 Deallocation routine. More...
 
void * IlMalloc (std::size_t nBytes)
 Allocation routine. More...
 
void * IlMemMove (void *destination, const void *source, std::size_t size)
 Allocation routine. More...
 
void * IlRealloc (void *block, std::size_t size)
 Re-allocation routine. More...
 

Detailed Description

Library: ilog Declaration of common memory management routines and macros used in Rogue Wave visualization products.

Macro Definition Documentation

#define IL_MALLOC (   type,
 
)

Allocates an array of objects.

The allocation is perfomed using IlMalloc() that is invoked with a total size of n * sizeof(type) bytes.

Note that if type has a constructor, it is not invoked by this macro. This macro is therefore dedicated to allocated arrays of simple types.

A typical use of this macro is:

// Allocate an array of 100 doubles.
IlDouble* array = IL_MALLOC(IlDouble, 100);
Parameters
typeThe object type.
nThe number of memory slots to allocate.
Returns
A pointer to a memory location able to store up to n objects of type type or 0 if this memory could not be obtained from the system.
The returned type is a type*and must be released by a call to IlFree().
#define IL_REALLOC (   type,
  array,
 
)

Re-allocates an array of objects.

The re-allocation is perfomed using IlRealloc() that is invoked with a total size of n * sizeof(type) bytes.

Note that if type has a constructor, it is not invoked by this macro. This macro is therefore dedicated to allocated arrays of simple types.

A typical use of this macro is:

// Allocate an array of 100 doubles.
IlDouble* array = IL_MALLOC(IlDouble, 100);
// ...
// Enlarge the array of doubles:
array = IL_REALLOC(IlDouble, array, 300);
Parameters
typeThe object type.
arrayThe initial array to be enlarged.
nThe number of memory slots to allocate.
Returns
A pointer to a memory location able to store up to n objects of type type or 0 if this memory could not be obtained from the system.
The returned type is a type* and must be released by a call to IlFree().
Note that the returned array may be (but does not have to be) the same as array.
See Also
IL_MALLOC().
#define IL_STRCASECMP (   s1,
  s2 
)

Compares two strings in a case-insensitive manner.

This macro provides a portable version of _stricmp() (or strcasecmp()). It compares two specified strings, ignoring their case, and returns an integer that indicates their relative position in the lexical order.

Parameters
s1The first string to compare.
s2The second string to compare.
Returns
The result of _stricmp(s1, s2) (or the equivalent function of the target platform).
#define IL_STRNCASECMP (   s1,
  s2,
 
)

Compares two strings in a case-insensitive manner.

This macro provides a portable version of _strnicmp() (or strncasecmp()). It compares two specified strings, ignoring their case, up to n characters, and returns an integer that indicates their relative position in the lexical order.

Parameters
s1The first string to compare.
s2The second string to compare.
nThe number of characters to compare.
Returns
The result of _strnicmp(s1, s2, n) (or the equivalent function of the target platform).

Function Documentation

char* IlCopyString ( const char *  string,
IlBoolean  zeroIfEmpty = IlTrue 
)

Allocates and returns a copy of a string.

Memory for the string copy is allocated using the new [] operator, and must therefore be released using the delete [] operator.

Parameters
stringThe string to be copied.
zeroIfEmptyIndicates, if IlTrue, that 0 should be returned if the input string is empty. If zeroIfEmpty is IlFalse and string is an empty string, then a new empty string is allocated and returned.
Returns
A new string where string is copied. The returned value is 0 if string is 0, or if string is empty and zeroIfEmpty is set to IlTrue.
void IlFree ( void *  block)

Deallocation routine.

This function is a portable version of free(). It releases a chunk of raw memory that was created by IlMalloc().

Parameters
blockA pointer to the memory block that was obtained by IlMalloc().
void* IlMalloc ( std::size_t  nBytes)

Allocation routine.

This function is a portable version of malloc(). It allocates raw memory that must be released by IlFree().

Parameters
nBytesThe number of bytes to be allocated.
Returns
A pointer to the memory block that was allocated, or 0 if this memory could not be obtained from the system.
void* IlMemMove ( void *  destination,
const void *  source,
std::size_t  size 
)

Allocation routine.

This function is a portable version of memmove(). It copies bytes from a memory location to another.

Parameters
destinationThe destination array where the content of source is to be copied. It must be able to store at least size consecutive bytes.
sourceThe source array to be copied. It must be able to access at least size consecutive bytes.
sizeThe number of bytes to be copied.
Returns
The value of destination.
void* IlRealloc ( void *  block,
std::size_t  size 
)

Re-allocation routine.

This function is a portable version of realloc(). It re-allocates raw memory that was allocated by IlMalloc(), and that must be released by IlFree(). It is typically used to enlarge a previously allocated memory block.

Parameters
blockThe initial memory block to be enlarged.
sizeThe number of bytes to be allocated.
Returns
A pointer to the new memory block that was allocated, or 0 if this memory could not be obtained from the system. This pointer can be (but does not have to be) the same as block.

© Copyright 2015, Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.