APPFS
Advanced practical programming for scientists
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
allocate.h File Reference

Wrapper for malloc. More...

Go to the source code of this file.

Functions

void * allocate (int elems, int size)
 Allocate memory. More...
 
void deallocate (void *p)
 Free allocated memory. More...
 

Detailed Description

Author
Thorsten Koch
Id:
allocate.h,v 1.4 2004/05/13 12:12:42 bzfkocht Exp

Definition in file allocate.h.

Function Documentation

void* allocate ( int  elems,
int  size 
)

If no memory is available the program will be terminated. The minimum allocation is 1 byte. Memory is initialized to zero, or false in case of bool.

Parameters
elemsnumber of elements
sizesize of one element in bytes
Returns
pointer to memory area of min elems * size bytes

Definition at line 23 of file allocate.c.

24 {
25  void* p;
26 
27  assert(elems > 0);
28  assert(size > 0);
29 
30  if (NULL == (p = calloc((size_t)elems, (size_t)size)))
31  {
32  perror("allocate");
33  exit(EXIT_FAILURE);
34  }
35  assert(p != NULL);
36 
37  return p;
38 }
int size
Maximale Anzahl von Elementen in der Queue.
Definition: queue.c:25
#define calloc(a, b)
Definition: mshell.h:54
void deallocate ( void *  p)

Releases the previous allocated memory. It should only be used with memory that has been allocated by allocate .

Parameters
pPointer to memory area that was previously returned by allocate

Definition at line 47 of file allocate.c.

48 {
49  assert(p != NULL);
50 
51  free(p);
52 }
#define free(a)
Definition: mshell.h:57