#include <stdio.h>#include <string.h>#include <malloc.h>#include <assert.h>Go to the source code of this file.
Compounds | |
| struct | _FreeLink_t |
| struct | _FreeList_t |
Defines | |
| #define | __J2K__FreeList_H__ 1 |
Typedefs | |
| typedef _FreeLink_t | FreeLink_t |
| typedef _FreeList_t | FreeList_t |
Functions | |
| FreeList_t * | FreeList_create (register size_t sz) |
| void * | FreeList_calloc (FreeList_t *this) |
| void | FreeList_free (FreeList_t *this, void *dead) |
| void | FreeList_purge (FreeList_t *this) |
| void | FreeList_delete (FreeList_t *this) |
|
|
Definition at line 2 of file FreeList.h. |
|
|
|
|
|
|
|
|
Definition at line 56 of file FreeList.c. 00057 {
00058 /* The current head if ain't NULL
00059 - OR -
00060 the new allocated memory to be used and returned
00061 */
00062 register void* curr = NULL;
00063
00064 /* Make sure the object pointer is valid */
00065 assert( this != NULL );
00066
00067 if ( this->head != NULL )
00068 {
00069 /* Pop out of the FreeList stack a dead structure */
00070 curr = this->head;
00071 this->head = this->head->next;
00072 }
00073 else
00074 {
00075 /* No FreeList Link available, so do a real malloc */
00076 curr = malloc( this->size );
00077
00078 /* Make sure the memory was allocated */
00079 assert( curr != NULL );
00080 }
00081
00082 /* Zero out the NEW allocated structure */
00083 memset( curr, 0, this->size );
00084
00085 /* Here's your zero'ed out structure */
00086 return curr;
00087 }
|
|
|
Definition at line 19 of file FreeList.c. 00020 {
00021 FreeList_t* fl = (FreeList_t*)malloc( sizeof( FreeList_t ) );
00022
00023 /* Make sure the memory was allocated */
00024 assert( fl != NULL );
00025
00026 /* Initialized the head, else purge and other won't work */
00027 fl->head = NULL;
00028
00029 /* Make sure the allocate data can be convert into 'FreeLink_t* next' pointers */
00030 if ( sz >= sizeof( FreeLink_t* ) )
00031 {
00032 /* It's big enough */
00033 fl->size = sz;
00034 }
00035 else
00036 {
00037 /* Make it big enough */
00038 fl->size = sizeof( FreeLink_t* );
00039 }
00040
00041 #ifdef __J2K__DEBUG_TRACE
00042 printf( "Needed space: [%d]\n", sz );
00043 printf( "Allocated space: [%d]\n", fl->size );
00044 printf( "FreeList space: [%d]\n", sizeof( FreeList_t ) );
00045 fflush( stdout );
00046 #endif
00047
00048 /* Here's your initialized empty FreeList */
00049 return fl;
00050 }
|
|
|
Definition at line 129 of file FreeList.c. 00130 {
00131 /* Make sure the object pointer is valid */
00132 assert( this != NULL );
00133
00134 /* Free every link */
00135 FreeList_purge( this );
00136
00137 /* Free the object itself */
00138 free( this );
00139 }
|
|
||||||||||||
|
Definition at line 94 of file FreeList.c. 00095 {
00096 /* Make sure the object pointer is valid */
00097 assert( this != NULL );
00098
00099 /* Convert the dead structure to a link to be stack up */
00100 FreeLink_t* link = (FreeLink_t*)dead;
00101 link->next = this->head;
00102 this->head = link;
00103 }
|
|
|
Definition at line 108 of file FreeList.c. Referenced by FreeList_delete().
00109 {
00110 /* Current purging pointer */
00111 register FreeLink_t* curr = NULL
00112
00113 /* Make sure the object pointer is valid */
00114 assert( this != NULL );
00115
00116 /* Go through the entire list and free every link */
00117 while( this->head != NULL )
00118 {
00119 curr = this->head;
00120 this->head = this->head->next;
00121 free( curr );
00122 }
00123 }
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001