CXXR (C++ R)
Namespaces | Functions | Variables
RAllocStack.cpp File Reference

($Id: RAllocStack.cpp 1348 2013-02-25 17:49:03Z arr $)

#include "CXXR/RAllocStack.h"
#include <cstring>
#include <stdexcept>
#include "R_ext/Error.h"
#include "localization.h"
#include "CXXR/MemoryBank.hpp"
Include dependency graph for RAllocStack.cpp:

Namespaces

namespace  CXXR
 Namespace for the CXXR project.

Functions

char * R_alloc (size_t num_elts, int elt_size)
 Allocate a block of memory.
char * S_alloc (long num_elts, int elt_size)
 Allocate a block of memory, and initialize it to zero.
char * S_realloc (char *prev_block, long new_sz, long old_sz, int elt_size)
 Reallocate a block of memory.

Variables

void *(* CXXR::ForceNonInline::vmaxgetp )(void) = vmaxget
void(* CXXR::ForceNonInline::vmaxsetp )(const void *) = vmaxset

Detailed Description

Implementation of class RAllocStack and related functions.


Function Documentation

char* R_alloc ( size_t  num_elts,
int  elt_size 
)

Allocate a block of memory.

This function is provided primarily for the use of code called from the R .C function. It will allocate a block of memory that will automatically be reclaimed by R at the end of the .C call.

Parameters:
num_eltsNumber of data items to be accommodated in the block.
elt_sizeSize in bytes (strictly, as a multiple of sizeof(char)) of each data item. Must be non-negative.
Returns:
Pointer to the start of the memory block.
Note:
The signed type of elt_size is anomalous, but is part of the R API.
char* S_alloc ( long  num_elts,
int  elt_size 
)

Allocate a block of memory, and initialize it to zero.

This is part of the S compatibility interface. It does the same thing as R_alloc(), except that the memory block is guaranteed to be initialized to zero.

Parameters:
num_eltsNumber of data items to be accommodated in the block. Must be non-negative.
elt_sizeSize in bytes (strictly, as a multiple of sizeof(char)) of each data item. Must be non-negative.
Returns:
Pointer to the start of the memory block.
char* S_realloc ( char *  prev_block,
long  new_sz,
long  old_sz,
int  elt_size 
)

Reallocate a block of memory.

This is part of the S compatibility interface, and is used when it is decided that a block of memory previously allocated by S_alloc() or S_realloc() needs to be expanded. It allocates a new block of memory, copies across the previous contents, and zeroes any additional elements.

Parameters:
prev_blockPointer to a block of memory previously allocated by S_alloc() or S_realloc().
new_szNew number of elements (>= 0) to be accommodated.
old_szNumber of elements contained in prev_block.
elt_sizeSize in bytes (strictly, as a multiple of sizeof(char)) of each data item. Must be non-negative.
Returns:
Pointer to the start of the newly allocated memory block. If new_sz <= old_sz, the function does not allocate a new block, and simply returns prev_block.