Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Beta/fast_alloc.c File Reference

#include "fast_alloc.h"

Go to the source code of this file.

Defines

#define __J2K__FAST_ALLOC_C__   1

Functions

size_t fast_mem_size (register size_t min_size)
void * fast_malloc (register size_t min_size)
void * fast_realloc (register void *buffer, register size_t buf_size, register size_t extra)
void fast_free (void *buffer)


Define Documentation

#define __J2K__FAST_ALLOC_C__   1
 

Definition at line 2 of file fast_alloc.c.


Function Documentation

void fast_free void *    buffer
 

Definition at line 90 of file fast_alloc.c.

00091 {
00092   free( buffer );
00093 }

void* fast_malloc register size_t    min_size
 

Definition at line 63 of file fast_alloc.c.

00064 {
00065   if ( min_size < 16 ) min_size = 16;
00066 
00067   void* buffer = malloc( fast_mem_size( min_size ) );
00068 
00069   /* Make sure we have some memory allocated ! */
00070   assert( buffer != NULL );
00071 
00072   return buffer;
00073 }

size_t fast_mem_size register size_t    min_size
 

Definition at line 24 of file fast_alloc.c.

00025 {
00026   register size_t  alloc_size = 1;
00027   register size_t  curr_size  = min_size;
00028 
00029   curr_size += MALLOC_MIN_OVERHEAD;
00030 
00031   if ( curr_size >= MALLOC_MAX_THRESHOLD ) 
00032   {
00033     curr_size >>= MALLOC_MAX_THRESHOLD_BIT;
00034     curr_size++;
00035     curr_size <<= MALLOC_MAX_THRESHOLD_BIT;
00036     alloc_size = curr_size;
00037   }
00038   else /* Too small, so exponential growth */
00039   {
00040     while( curr_size > 0 ) 
00041     {
00042       curr_size  >>= 1;  /* Get the highest power of two + 1 bit */
00043       alloc_size <<= 1;
00044     }
00045   }
00046 
00047 #ifdef __J2K__DEBUG_TRACE
00048   printf( "Wanted space:    [%d]\n", min_size   );
00049   printf( "Allocated space: [%d]\n", alloc_size );
00050   printf( "malloc'ed space: [%d]\n", alloc_size - MALLOC_MIN_OVERHEAD );
00051   fflush( stdout );
00052 #endif
00053 
00054   alloc_size -= MALLOC_MIN_OVERHEAD;
00055   
00056   /* Make sure what we allocate is big enough */
00057   assert( alloc_size >= curr_size );  
00058 
00059   return alloc_size;
00060 }

void* fast_realloc register void *    buffer,
register size_t    buf_size,
register size_t    extra
 

Definition at line 76 of file fast_alloc.c.

00077 {
00078   if ( extra < 16 ) extra = 16;
00079 
00080   register size_t sz = fast_mem_size( extra ) + buf_size;
00081   void* buffer = realloc( buffer, sz );
00082 
00083   /* Make sure we have some memory allocated ! */
00084   assert( buffer != NULL );
00085 
00086   return buffer;
00087 }


Generated on Sun Oct 14 18:46:50 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001