Memory allocation:

All arrays in pdo are dynamic - variable size. I never know how many patches to 
handle - few or over thousands, as well as how big each patch record will be. 
Biggest problem with database was the fact that it has fixed field sizes and so 
has always a lot of memory wasted - for example database table (stored in the 
file) which substitute contents file in Registry 4 project was as I remember 
more then 10 times bigger then "inefficient" contents file with same data.

To allocate memory I use schema suggested to me by Bart - to avoid frequent 
reallocation it create some pool for data to fill without reallocation which is 
naturally heavy operation. If pool is filled I reallocate twice memory then 
array currently has. It works pretty well and in worst case I have 
overallocated bit less then twice needed memory, but anyway nature of the data 
I have - mostly longs and so it is nothing in comparison with today memory 
sizes. This schema works always if I need to reallocate memory. To support this 
in addition to array itself which is pointer to allocated memory, I have 
current position in the pool of free memory and size of currently allocated 
chunk. This pattern you may found all over pdo code.

static long            array_num;
static long            array_realloc_limit;
static array_type  *array;

       array_num++;
       if (array_num > array_realloc_limit) {
               array_realloc_limit = 2 * array_realloc_limit;
               array = xrealloc(array,  (sizeof (array_type)) * 
array_realloc_limit);

Realloc by the way impossible to use if you have direct links, but with 
reference indexes - no problem.

vassun
 
 
This message posted from opensolaris.org

      • ... ನರೇಂದ ್ರ ಕು ಮಾರ್. ಎಸ್.ಎಸ ್(Narendra Kumar.S.S)
    • ... Vasiliy
  • ... Vasiliy
  • ... Vasiliy
  • ... Vasiliy
  • ... Vasiliy
  • ... Vasiliy
  • ... Vasiliy
  • ... Vasiliy
  • ... Vasiliy
    • ... Vasiliy
    • ... Narendra Kumar S.S
      • ... Vasiliy
        • ... Glenn Lagasse
  • ... Vasiliy
    • ... senthil k narayanasamy
      • ... Bob Palowoda

Reply via email to