int main( int ac, char **av ) { int *nlen; static char **name, **seq; double score; extern double score_calc_for_score( int, char ** ); arguments( ac, av ); getnumlen( stdin ); rewind( stdin ); nlen = AllocateIntVec( njob ); name = AllocateCharMtx( njob, B+1 ); seq = AllocateCharMtx( njob, nlenmax+2 ); readData_pointer( stdin, name, nlen, seq ); if( !isaligned( njob, seq ) ) ErrorExit( "Not aligned." ); constants( njob, seq ); score = score_calc_for_score( njob, seq ); if( scoremtx == 0 ) score += offset; fprintf( stdout, "score = %f\n", score ); if ( scoremtx == 0 ) fprintf( stdout, "JTT %dPAM\n", pamN ); else if( scoremtx == 1 ) fprintf( stdout, "Dayhoff( machigai ga aru )\n" ); else if( scoremtx == 2 ) fprintf( stdout, "M-Y\n" ); else if( scoremtx == -1 ) fprintf( stdout, "DNA 1:%d\n", kimuraR ); fprintf( stdout, "gap penalty = %+6.2f, %+6.2f, %+6.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 ); exit( 0 ); }
void CMPage::Clear(void) { if (!Is_Empty()) { m_freeblock_num = m_allblock_num; assert(isaligned(m_block, m_align_size) && "memory not aligned"); m_freeblock_head = (FreeBlock*)m_block; m_freeblock_head->next = 0; } }
static errcode_t test_memalign(unsigned long align) { void *ptr = 0; errcode_t retval; retval = ext2fs_get_memalign(32, align, &ptr); if (!retval && !isaligned(ptr, align)) retval = EINVAL; free(ptr); printf("tst_memalign(%lu) is %s\n", align, retval ? error_message(retval) : "OK"); return retval; }
void CMPage::Free(void* ptr) { // 检测Pool是否分配以及待释放指针是否为空, 以防止发生错误 if (!ptr) return; if (Is_ContainsPointer(ptr) && isaligned(ptr, m_align_size)) { // 将释放的内存还给Pool freeblock((FreeBlock*)ptr); } else { assert(false && "object not allocated from this pool"); } }
void CMPage::create(unsigned long block_size, unsigned long align_size) { unsigned long src_pagesize = Get_PageSize(); // 得到对齐后的一个block的内存大小,每个block必须大于sizeof(FreeBlock*) m_block_size = Calc_AlignedSize(block_size, align_size); m_align_size = align_size; // 首先是维护FreeBlock指针占用的内存大小 //unsigned long pointersize = sizeof(FreeBlock*); unsigned long maxfilledsize = m_align_size - 1; if (m_block_size + maxfilledsize > DEFAULT_PAGESIZE) { m_page_size = m_block_size + maxfilledsize; m_allblock_num = 1; } else { m_page_size = DEFAULT_PAGESIZE; m_allblock_num = (m_page_size - maxfilledsize) / m_block_size; } m_freeblock_num = m_allblock_num; // 如果原来的跟现在的内存一样大小 就不再分配 if (m_memory || src_pagesize != m_page_size) { if (m_memory) { ::free(m_memory); } m_memory = ::malloc(m_page_size); } m_block = getaligned(m_memory, m_align_size); // 检测分配内存是否满足内存对齐条件, assert(isaligned(m_block, m_align_size) && "memory not aligned"); // 将FreeBlock链表头设置为分配的值 m_freeblock_head = (FreeBlock*)m_block; m_freeblock_head->next = 0; }