next up previous 264
Next: astString - Create a C string from an array of characters
Up: AST Memory Management and Utility Functions
Previous: astSizeOf - Determine the size of a dynamically allocated region of memory


astStore - Store data in dynamically allocated memory

Description:
This function stores data in dynamically allocated memory, allocating the memory (or adjusting the size of previously allocated memory) to match the amount of data to be stored.
Synopsis:
void $*$astStore( void $*$ptr, const void $*$data, size_t size )
Parameters:
ptr
Pointer to previously allocated memory (or NULL if none has yet been allocated).
data
Pointer to the start of the data to be stored. This may be given as NULL if there are no data, in which case it will be ignored and this function behaves like astRealloc, preserving the existing memory contents.
size
The total size of the data to be stored and/or the size of memory to be allocated. This may be zero, in which case the data parameter is ignored, any previously-allocated memory is freed and a NULL pointer is returned.
Returned Value:
astStore()
If the data were stored successfully, a pointer to the start of the possibly new memory region is returned (this may be the same as the original pointer). If size was given as zero, a NULL pointer is returned.
Notes:
  • This is a convenience function for use when storing data of arbitrary size in memory which is to be allocated dynamically. It is appropriate when the size of the data will not change frequently because the size of the memory region will be adjusted to fit the data on every invocation.

  • If this function is invoked with the error status set, or if it fails for any reason, the original pointer value is returned and the memory contents are unchanged.


next up previous 264
Next: astString - Create a C string from an array of characters
Up: AST Memory Management and Utility Functions
Previous: astSizeOf - Determine the size of a dynamically allocated region of memory

AST A Library for Handling World Coordinate Systems in Astronomy
Starlink User Note 211
R.F. Warren-Smith & D.S. Berry
24th May 2011
E-mail:ussc@star.rl.ac.uk

Copyright (C) 2009 Science \& Technology Facilities Council