Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
dynarrc/dynarrc/dynarrc.coremethods.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69 lines (62 sloc)
2.91 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a global dynarr struct containing all state variables for given type | |
#define SEG_ARR_CREATE(type) \ | |
DYNARR_STATE(type) DYNARR_VARS(type); | |
// use the global dynarr struct containing all state variables for given type | |
#define SEG_ARR_USE(type) \ | |
extern SEG_ARR_CREATE(type); | |
// initialize all state variables in the global dynarr struct for given type | |
#define SEG_ARR_INIT(type) do{\ | |
if(INITIALIZED_FLAG(type) == 0) { \ | |
/*MaxSeg should be already assigned */ \ | |
assert(MAXSEG > 0 ); \ | |
LOGMAXSEG(type) = (unsigned int) (log(MAXSEG+0.0f)/log(2.0f)); \ | |
MAXSEG_REMAINDER_BITMASK(type) = (unsigned int) (MAXSEG - 1); \ | |
NULL_SEG(type).index = NULL_SEG(type).nextIndex = EMPTY_INDEX; \ | |
/* seg-arr management */ \ | |
SEG_ARR(type) = ( DYNARR_SEG_TYPE(type) *) malloc( sizeof(DYNARR_SEG_TYPE(type) ) * MAXSEG ); \ | |
assert(SEG_ARR(type) != NULL ); \ | |
memset(SEG_ARR(type), 0, sizeof(DYNARR_SEG_TYPE(type)) * MAXSEG ); \ | |
SEG_INSERT_POS(type) = SEG_INSERT_POS_BEGIN; \ | |
/*------------------------------------*/ \ | |
/* multiple segment banks */ \ | |
/* In test mode, do not initalize MaxSegBanks here so that */ \ | |
/* it can be initialized by other code before calling SEG_BANKS_INIT() */ \ | |
/*if (!TestEnabled) MAX_SEG_BANKS(type) = 1; */ \ | |
MAX_SEG_BANKS(type) = 1; /* Default value */ \ | |
TOTAL_SEGS(type) = 0; /* Default value */ \ | |
SEG_BANK_ALLOC_VIOLATION(type) = 0; \ | |
/* segment banks*/ \ | |
SEG_BANKS_ARR(type) = (DYNARR_SEG_TYPE(type)**)malloc(MAX_SEG_BANKS(type) * sizeof(DYNARR_SEG_TYPE(type)*)); \ | |
memset(SEG_BANKS_ARR(type), 0, MAX_SEG_BANKS(type) * sizeof(DYNARR_SEG_TYPE(type)*)); \ | |
/* segment bank sizes*/ \ | |
SEG_BANK_SIZE_ARR(type) = (int*)malloc(MAX_SEG_BANKS(type) * sizeof(int)); \ | |
memset(SEG_BANK_SIZE_ARR(type), 0, MAX_SEG_BANKS(type) * sizeof(int)); \ | |
/* segment bank index limits */ \ | |
SEG_BANK_INDEX_LIMIT_ARR(type) = (int*)malloc(MAX_SEG_BANKS(type) * sizeof(int)); \ | |
memset(SEG_BANK_INDEX_LIMIT_ARR(type), 0, MAX_SEG_BANKS(type) * sizeof(int)); \ | |
/* first segment bacnk already allocated */ \ | |
SEG_BANKS_ARR(type)[0] = SEG_ARR(type); \ | |
SEG_BANK_SIZE_ARR(type)[0] = MAXSEG; \ | |
SEG_BANK_INDEX_LIMIT_ARR(type)[0] = MAXSEG - 1; \ | |
NUM_SEG_BANKS(type) = 1; \ | |
INITIALIZED_FLAG(type) = 1; \ | |
} \ | |
}while(0) | |
// cleanup all state variables in the global dynarr struct for given type | |
#define SEG_ARR_CLEANUP(type) do{\ | |
FREE_SAFE( SEG_ARR(type) ); \ | |
SEG_INSERT_POS(type) = SEG_INSERT_POS_BEGIN; \ | |
/*-------------------------------*/ \ | |
/* multiple segment banks */ \ | |
for(TEMP_INDEX_1(type) = 1; TEMP_INDEX_1(type) < NUM_SEG_BANKS(type); TEMP_INDEX_1(type)++){ \ | |
FREE_SAFE(SEG_BANKS_ARR(type)[TEMP_INDEX_1(type)]); \ | |
} \ | |
NUM_SEG_BANKS(type) = 0; \ | |
FREE_SAFE(SEG_BANKS_ARR(type)); \ | |
FREE_SAFE(SEG_BANK_SIZE_ARR(type)); \ | |
FREE_SAFE(SEG_BANK_INDEX_LIMIT_ARR(type)); \ | |
SEG_BANK_ALLOC_VIOLATION(type) = 0; \ | |
_SEG_ARR_FREE_LIST_CLEANUP(type); \ | |
TOTAL_SEGS(type) = 0; \ | |
INITIALIZED_FLAG(type) = 0; \ | |
}while(0) |