void *judy_data (Judy *judy, uint amt) { JudySeg *seg; void *block; if( amt & 0x07 ) amt |= 0x07, amt += 1; if( !judy->seg || judy->seg->next < amt + sizeof(*seg) ) { if( (seg = valloc (JUDY_seg)) ) { seg->next = JUDY_seg, seg->seg = judy->seg, judy->seg = seg; } else { #ifdef STANDALONE judy_abort("Out of virtual memory"); #else return NULL; #endif } #ifdef STANDALONE MaxMem += JUDY_seg; #endif } judy->seg->next -= amt; block = (void *)((uchar *)judy->seg + judy->seg->next); memset (block, 0, amt); return block; }
void *judy_open (uint max) { JudySeg *seg; Judy *judy; uint amt; if( (seg = valloc(JUDY_seg)) ) { seg->next = JUDY_seg; } else { #ifdef STANDALONE judy_abort ("No virtual memory"); #else return NULL; #endif } amt = sizeof(Judy) + max * sizeof(JudyStack); #ifdef STANDALONE MaxMem += JUDY_seg; #endif if( amt & 0x07 ) amt |= 0x07, amt++; seg->next -= amt; judy = (Judy *)((uchar *)seg + seg->next); memset(judy, 0, amt); judy->seg = seg; judy->max = max; return judy; }
void * judy_data( Judy * judy, unsigned int amt ) { JudySeg * seg; void * block; if( !judy->seg ) #if defined(STANDALONE) || defined(ASKITIS) judy_abort( "illegal allocation from judy clone" ); #else return NULL; #endif if( amt & ( JUDY_cache_line - 1 ) ) { amt |= ( JUDY_cache_line - 1 ), amt += 1; } if( judy->seg->next < amt + sizeof( *seg ) ) { if( ( seg = malloc( JUDY_seg ) ) ) { seg->next = JUDY_seg; seg->seg = judy->seg; judy->seg = seg; seg->next -= ( JudySlot )seg & ( JUDY_cache_line - 1 ); } else { #if defined(STANDALONE) || defined(ASKITIS) judy_abort( "Out of virtual memory" ); #else return NULL; #endif } #if defined(STANDALONE) || defined(ASKITIS) MaxMem += JUDY_seg; #endif } judy->seg->next -= amt; block = ( void * )( ( unsigned char * )judy->seg + judy->seg->next ); memset( block, 0, amt ); return block; }
void *judy_alloc (Judy *judy, int type) { void **block; JudySeg *seg; uint amt; amt = JudySize[type]; if( amt & 0x07 ) amt |= 0x07, amt += 1; if( (block = judy->reuse[type]) ) { judy->reuse[type] = *block; memset (block, 0, amt); return (void *)block; } if( !judy->seg || judy->seg->next < amt + sizeof(*seg) ) { if( (seg = valloc (JUDY_seg)) ) { seg->next = JUDY_seg, seg->seg = judy->seg, judy->seg = seg; } else { #ifdef STANDALONE judy_abort("Out of virtual memory"); #else return NULL; #endif } #ifdef STANDALONE MaxMem += JUDY_seg; #endif } judy->seg->next -= amt; block = (void **)((uchar *)judy->seg + judy->seg->next); memset (block, 0, amt); return (void *)block; }
Judy * judy_open( unsigned int max, unsigned int depth ) { JudySeg * seg; Judy * judy; unsigned int amt; max++; // allow for zero terminator on keys if( ( seg = malloc( JUDY_seg ) ) ) { seg->seg = NULL; seg->next = JUDY_seg; } else { #if defined(STANDALONE) || defined(ASKITIS) judy_abort( "No virtual memory" ); #else return NULL; #endif } amt = sizeof( Judy ) + max * sizeof( JudyStack ); if( amt & ( JUDY_cache_line - 1 ) ) { amt |= JUDY_cache_line - 1, amt++; } #if defined(STANDALONE) || defined(ASKITIS) MaxMem += JUDY_seg; #endif seg->next -= ( JudySlot )seg & ( JUDY_cache_line - 1 ); seg->next -= amt; judy = ( Judy * )( ( unsigned char * )seg + seg->next ); memset( judy, 0, amt ); judy->depth = depth; judy->seg = seg; judy->max = max; return judy; }
void *judy_open (uint max) { JudySeg *seg; Judy *judy; uint amt; max++; // allow for zero terminator on keys if( (seg = malloc(JUDY_seg)) ) { seg->seg = NULL; seg->next = JUDY_seg; } else { #ifdef STANDALONE judy_abort ("No virtual memory"); #else return NULL; #endif } amt = sizeof(Judy) + max * sizeof(JudyStack); if( amt & (JUDY_cache_line - 1) ) amt |= JUDY_cache_line - 1, amt++; #ifdef STANDALONE MaxMem += JUDY_seg; #endif seg->next -= (JudySlot)seg & (JUDY_cache_line - 1); seg->next -= amt; judy = (Judy *)((uchar *)seg + seg->next); memset(judy, 0, amt); judy->seg = seg; judy->max = max; return judy; }
void *judy_alloc (Judy *judy, int type) { uint amt, idx; JudySeg *seg; void **block; if( !judy->seg ) #ifdef STANDALONE judy_abort("illegal allocation from judy clone"); #else return NULL; #endif if( type == JUDY_radix ) type = JUDY_radix_equiv; if( type == JUDY_span ) type = JUDY_span_equiv; amt = JudySize[type]; if( amt & 0x07 ) amt |= 0x07, amt += 1; // see if free block is already available if( (block = judy->reuse[type]) ) { judy->reuse[type] = *block; memset (block, 0, amt); return (void *)block; } // break down available larger block // for reuse into smaller blocks if( type >= JUDY_1 ) for( idx = type; idx++ < JUDY_max; ) if( block = judy->reuse[idx] ) { judy->reuse[idx] = *block; while( idx-- > type) { judy->reuse[idx] = block + JudySize[idx] / sizeof(void *); block[JudySize[idx] / sizeof(void *)] = 0; } memset (block, 0, amt); return (void *)block; } if( judy->seg->next < amt + sizeof(*seg) ) { if( (seg = valloc (JUDY_seg)) ) { seg->next = JUDY_seg, seg->seg = judy->seg, judy->seg = seg; } else { #ifdef STANDALONE judy_abort("Out of virtual memory"); #else return NULL; #endif } #ifdef STANDALONE MaxMem += JUDY_seg; #endif } judy->seg->next -= amt; block = (void **)((uchar *)judy->seg + judy->seg->next); memset (block, 0, amt); return (void *)block; }
void *judy_alloc (Judy *judy, uint type) { uint amt, idx, min; JudySeg *seg; void **block; void **rtn; if( !judy->seg ) #ifdef STANDALONE judy_abort("illegal allocation from judy clone"); #else return NULL; #endif if( type == JUDY_radix ) type = JUDY_radix_equiv; if( type == JUDY_span ) type = JUDY_span_equiv; amt = JudySize[type]; if( amt & 0x07 ) amt |= 0x07, amt += 1; // see if free block is already available if( (block = judy->reuse[type]) ) { judy->reuse[type] = *block; memset (block, 0, amt); return (void *)block; } // break down available larger block // for reuse into smaller blocks if( type >= JUDY_1 ) for( idx = type; idx++ < JUDY_max; ) if( block = judy->reuse[idx] ) { judy->reuse[idx] = *block; while( idx-- > type) { judy->reuse[idx] = block + JudySize[idx] / sizeof(void *); block[JudySize[idx] / sizeof(void *)] = 0; } memset (block, 0, amt); return (void *)block; } min = amt < JUDY_cache_line ? JUDY_cache_line : amt; if( judy->seg->next < min + sizeof(*seg) ) { if( (seg = malloc (JUDY_seg)) ) { seg->next = JUDY_seg; seg->seg = judy->seg; judy->seg = seg; seg->next -= (JudySlot)seg & (JUDY_cache_line - 1); } else { #ifdef STANDALONE judy_abort("Out of virtual memory"); #else return NULL; #endif } #ifdef STANDALONE MaxMem += JUDY_seg; #endif } // generate additional free blocks // to fill up to cache line size rtn = (void **)((uchar *)judy->seg + judy->seg->next - amt); for( idx = type; amt & (JUDY_cache_line - 1); amt <<= 1 ) { block = (void **)((uchar *)judy->seg + judy->seg->next - 2 * amt); judy->reuse[idx++] = block; *block = 0; } judy->seg->next -= amt; memset (rtn, 0, JudySize[type]); return (void *)rtn; }