AcePerl
view release on metacpan or search on metacpan
acelib/memsubs.c view on Meta::CPAN
/* File: memsubs.c
* Author: Richard Durbin (rd@sanger.ac.uk)
* Copyright (C) J Thierry-Mieg and R Durbin, 1998
*-------------------------------------------------------------------
* This file is part of the ACEDB genome database package, written by
* Richard Durbin (MRC LMB, UK) rd@sanger.ac.uk, and
* Jean Thierry-Mieg (CRBM du CNRS, France) mieg@kaa.cnrs-mop.fr
*
* Description:
* Exported functions:
* HISTORY:
* Last edited: Dec 4 11:24 1998 (fw)
* Created: Thu Aug 20 16:54:55 1998 (rd)
*-------------------------------------------------------------------
*/
/* define MALLOC_CHECK here to check mallocs - also in regular.h */
#include "regular.h"
#if defined(NEXT) || defined(HP) || defined(MACINTOSH)
extern void* malloc(mysize_t size) ;
#elif !defined(WIN32) && !defined(DARWIN)
#include <malloc.h> /* normal machines */
#endif
/********** primary type definition **************/
typedef struct _STORE_HANDLE_STRUCT {
STORE_HANDLE next ; /* for chaining together on Handles */
STORE_HANDLE back ; /* to unchain */
void (*final)(void*) ; /* finalisation routine */
int size ; /* of user memory to follow */
#ifdef MALLOC_CHECK
int check1 ; /* set to known value */
#endif
} STORE_HANDLE_STRUCT ;
/*********************************************************************/
/********** memory allocation - messalloc() and handles *************/
static int numMessAlloc = 0 ;
static int totMessAlloc = 0 ;
/* Calculate to size of an STORE_HANDLE_STRUCT rounded to the nearest upward
multiple of sizeof(double). This avoids alignment problems when
we put an STORE_HANDLE_STRUCT at the start of a memory block */
#define STORE_OFFSET ((((sizeof(STORE_HANDLE_STRUCT)-1)/MALLOC_ALIGNMENT)+1)\
* MALLOC_ALIGNMENT)
/* macros to convert between a void* and the corresponding STORE_HANDLE */
#define toAllocUnit(x) (STORE_HANDLE) ((char*)(x) - STORE_OFFSET)
#define toMemPtr(unit)((void*)((char*)(unit) + STORE_OFFSET))
#ifdef MALLOC_CHECK
BOOL handlesInitialised = FALSE;
static Array handles = 0 ;
/* macro to give the terminal check int for an STORE_HANDLE_STRUCT */
/* unit->size must be a multiple of sizeof(int) */
#define check2(unit) *(int*)(((char*)toMemPtr(unit)) + (unit)->size)
static void checkUnit (STORE_HANDLE unit) ;
static int handleOrder (void *a, void *b)
{ return (*((STORE_HANDLE *)a) == *((STORE_HANDLE *)b)) ? 0 :
(*((STORE_HANDLE *)a) > *((STORE_HANDLE *)b)) ? 1 : -1 ;
}
#endif
( run in 1.651 second using v1.01-cache-2.11-cpan-99c4e6809bf )