Loading...
Searching...
No Matches
xalloc.h
Go to the documentation of this file.
#ifndef XMEMORY_H
#define XMEMORY_H
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT: omalloc simulation
*/
/* debug routines of omalloc are not implemented, but as dummies provided: */
#define OM_NDEBUG 1
/* use of Bins: define for optimal performancei(6%), undef for valgrind */
#define XALLOC_BIN 1
/* performancce of xalloc+XALLOC_BIN: +32.6 %, xalloc w/o XALLOC_BIN: +40.7 %
* (omalloc=100 %) */
#include <stdlib.h>
#include <string.h>
#include "omalloc/omConfig.h"
#ifdef __cplusplus
extern "C" {
#if __cplusplus >= 201402L
/* clang 3.7, gcc 5.1 sets 201402L */
#define REGISTER
#elif defined(__clang__)
#define REGISTER
#else
#define REGISTER register
#endif
#else
#define REGISTER register
#endif
struct omInfo_s;
typedef struct omInfo_s omInfo_t;
struct omInfo_s
{
long MaxBytesSystem; /* set in omUpdateInfo(), is more accurate with malloc support */
long CurrentBytesSystem; /* set in omUpdateInfo(), is more accurate with malloc support */
long MaxBytesSbrk; /* always up-to-date, not very accurate, needs omInintInfo() */
long CurrentBytesSbrk; /* set in omUpdateInfo(), needs omInintInfo() */
long MaxBytesMmap; /* set in omUpdateInfo(), not very accurate */
long CurrentBytesMmap; /* set in omUpdateInfo(), not very accurate */
long UsedBytes; /* set in omUpdateInfo() */
long AvailBytes; /* set in omUpdateInfo() */
long UsedBytesMalloc; /* set in omUpdateInfo(), needs malloc support */
long AvailBytesMalloc; /* set in omUpdateInfo(), needs malloc support */
long MaxBytesFromMalloc; /* always kept up-to-date */
long CurrentBytesFromMalloc; /* always kept up-to-date */
long MaxBytesFromValloc; /* always kept up-to-date */
long CurrentBytesFromValloc; /* always kept up-to-date */
long UsedBytesFromValloc; /* set in omUpdateInfo() */
long AvailBytesFromValloc;/* set in omUpdateInfo() */
long MaxPages; /* always kept up-to-date */
long UsedPages; /* always kept up-to-date */
long AvailPages; /* always kept up-to-date */
long MaxRegionsAlloc; /* always kept up-to-date */
long CurrentRegionsAlloc; /* always kept up-to-date */
};
extern struct omInfo_s om_Info;
struct omOpts_s;
extern struct omOpts_s
{
int MinTrack;
int MinCheck;
int MaxTrack;
int MaxCheck;
int Keep;
int HowToReportErrors;
int MarkAsStatic;
unsigned int PagesPerRegion;
void (*OutOfMemoryFunc)();
void (*MemoryLowFunc)();
void (*ErrorHook)();
} om_Opts;
typedef struct omOpts_s omOpts_t;
extern int om_sing_opt_show_mem;
#define omalloc(s) malloc(s)
#define omAlloc(s) malloc(s)
static inline void * omAlloc0(size_t s)
{ void *d=malloc(s);memset(d,0,s); return d; }
static inline void * omalloc0(size_t s)
{ if (s!=0) { void *d=malloc(s);memset(d,0,s); return d;} else return NULL; }
static inline void *omRealloc0Size(void *d, __attribute__((unused)) size_t os, size_t ns)
{ if (d==NULL)
return omAlloc0(ns);
else
{
char *p=(char *)realloc(d,ns);
if (ns>os) memset(p+os,0,ns-os);
return (void*)p;
}
}
#define omfree(d) free(d)
#define omFree(d) free(d)
#define omFreeSize(d,s) free(d)
#define omStrDup(s) strdup(s)
#ifdef XALLOC_BIN
typedef struct omBin_next_s omBin_next_t;
typedef omBin_next_t* omBin_next;
struct omBin_next_s
{
omBin_next next;
};
struct omBin_s
{
omBin_next curr; /* current freelist */
size_t size; /* size in bytes */
};
typedef struct omBin_s omBin_t;
typedef omBin_t* omBin;
#define omSizeWOfBin(bin_ptr) (((bin_ptr->size)+SIZEOF_LONG-1)/SIZEOF_LONG)
static inline void* omAllocBin(omBin b)
{
if (b->curr!=NULL)
{
omBin_next p=b->curr;
b->curr=p->next;
return p;
}
else return omAlloc(b->size);
}
static inline void* omAlloc0Bin(omBin b)
{
if (b->curr!=NULL)
{
omBin_next p=b->curr;
b->curr=p->next;
memset(p,0,b->size);
return p;
}
else return omAlloc0(b->size);
}
static inline void omFreeBin(void *p, omBin b)
{
*((void**) p) = b->curr;
b->curr=(omBin_next)p;
}
#define omTypeAllocBin(T,P,B) P=(T)omAllocBin(B)
#define omTypeAlloc0Bin(T,P,B) P=(T)omAlloc0Bin(B)
static inline omBin omGetSpecBin(size_t s)
{
omBin b=(omBin)omAlloc(sizeof(*b));
b->size=s;
b->curr=NULL;
return b;
}
static inline void omUnGetSpecBin(omBin *A)
{
omBin_next p=(*A)->curr;
omBin_next pp;
while(p!=NULL)
{
pp=p->next;
omFree(p);
p=pp;
}
(*A)->curr=NULL;
omFree(*A);
}
#else
typedef size_t omBin;
#define omSizeWOfBin(bin_ptr) (((bin_ptr)+SIZEOF_LONG-1)/SIZEOF_LONG)
#define omTypeAllocBin(T,P,B) P=(T)omAlloc(B)
#define omTypeAlloc0Bin(T,P,B) P=(T)omAlloc0(B)
#define omAllocBin(B) omAlloc(B)
#define omAlloc0Bin(B) omAlloc0(B)
#define omFreeBin(P,B) omFree(P)
#define omGetSpecBin(A) (A)
#define omUnGetSpecBin(A) do {} while (0)
#endif
/*******************************************************************
*
* error codes
*
*******************************************************************/
enum omError_e
{
omError_NoError = 0,
omError_Unknown,
omError_InternalBug,
omError_MemoryCorrupted,
omError_NullAddr,
omError_InvalidRangeAddr,
omError_FalseAddr,
omError_FalseAddrOrMemoryCorrupted,
omError_WrongSize,
omError_FreedAddr,
omError_FreedAddrOrMemoryCorrupted,
omError_WrongBin,
omError_UnknownBin,
omError_NotBinAddr,
omError_UnalignedAddr,
omError_NullSizeAlloc,
omError_ListCycleError,
omError_SortedListError,
omError_KeptAddrListCorrupted,
omError_FreePattern,
omError_BackPattern,
omError_FrontPattern,
omError_NotString,
omError_StickyBin,
omError_MaxError
};
// typedef enum omError_e omError_t;
#define omSizeWOfAddr(P) (omSizeOfAddr(P)/SIZEOF_LONG)
#define omTypeAlloc(T,P,S) P=(T)omAlloc(S)
#define omAlloc0Aligned(S) omAlloc0(S)
#define omAllocAligned(S) omAlloc(S)
#define omInitInfo()
#define omInitGetBackTrace()
#define omUpdateInfo()
#define omPrintStats(F)
#define omPrintInfo(F)
#define omPrintBinStats(F)
#define omMarkMemoryAsStatic()
#define omfreeSize(P,S) free(P)
#define omFreeFunc free
#define omFreeBinAddr(P) free(P)
#define omrealloc(A,NS) realloc(A,NS)
#define omreallocSize(A,OS,NS) realloc(A,NS)
#define omrealloc0Size(A,OS,NS) omRealloc0Size(A,OS,NS)
#define omRealloc(A,B) realloc(A,B)
#define omReallocAligned(A,B) realloc(A,B)
#define omReallocSize(A,B,C) realloc(A,C)
#define omReallocAlignedSize(A,B) realloc(A,B)
#define omMarkAsStaticAddr(A)
#define omMemcpyW(A,B,C) memcpy(A,B,(C)*SIZEOF_LONG)
#define omGetStickyBinOfBin(B) (B)
/* debug dummies: */
#define omTypeReallocAlignedSize omTypeReallocSize
#define omTypeRealloc0AlignedSize omTypeRealloc0Size
#define omRealloc0AlignedSize omRealloc0Size
#define omMemDupAligned omMemDup
#define omCheckIf(cond, test) do {} while (0)
#define omCheckBinAddr(addr) do {} while (0)
#define omCheckAddrBin(addr,bin) do {} while (0)
#define omCheckBinAddrSize(addr,size) do {} while (0)
#define omCheckAddrSize(addr,size) do {} while (0)
#define omCheckAddr(addr) do {} while (0)
#define omcheckAddrSize(addr,size) do {} while (0)
#define omcheckAddr(addr) do {} while (0)
#define omCheckBin(bin) do {} while (0)
#define omCheckMemory() do {} while (0)
#define omPrintCurrentBackTraceMax(A,B) do {} while (0)
#define omPrintUsedTrackAddrs(F,max) do {} while (0)
#define omPrintCurrentBackTrace(F) do {} while (0)
#define omPrintUsedAddrs(F,max) do {} while (0)
#define omdebugAddrSize(A,B) do {} while (0)
#define omPrintAddrInfo(A,B,C) do {} while (0)
#define omIsBinPageAddr(A) (1)
#define omTestBinAddrSize(A,B,C) (omError_NoError)
#define omTestList(ptr, level) (omError_NoError)
#define omInitRet_2_Info(argv0) do {} while (0)
#define omMergeStickyBinIntoBin(A,B) do {} while (0)
#ifdef __cplusplus
}
#endif
#undef OMALLOC_USES_MALLOC
#define X_OMALLOC
#define omMallocFunc malloc
#define omFreeSizeFunc omFreeSize
#define omReallocSizeFunc realloc
/* #define OM_NDEBUG */
#undef OM_SING_KEEP
#endif
pp
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f ).
Definition cf_gcd.cc:676
p
int p
Definition cfModGcd.cc:4086
b
CanonicalForm b
Definition cfModGcd.cc:4111
s
const CanonicalForm int s
Definition facAbsFact.cc:51
__attribute__
#define __attribute__(x)
Definition mod2.h:429
omAllocBin
#define omAllocBin(bin)
Definition omAllocDecl.h:205
omAlloc0Bin
#define omAlloc0Bin(bin)
Definition omAllocDecl.h:206
omalloc0
#define omalloc0(size)
Definition omAllocDecl.h:229
omAlloc0
#define omAlloc0(size)
Definition omAllocDecl.h:211
omFreeBin
#define omFreeBin(addr, bin)
Definition omAllocDecl.h:259
omRealloc0Size
#define omRealloc0Size(addr, o_size, size)
Definition omAllocDecl.h:221
realloc
#define realloc
Definition omAllocFunc.c:16
malloc
#define malloc
Definition omAllocFunc.c:12
omGetSpecBin
#define omGetSpecBin(size)
Definition omBin.h:11
omUnGetSpecBin
#define omUnGetSpecBin(bin_ptr)
Definition omBin.h:14
omError_e
omError_e
Definition omError.h:17
omError_WrongSize
@ omError_WrongSize
Definition omError.h:26
omError_ListCycleError
@ omError_ListCycleError
Definition omError.h:34
omError_BackPattern
@ omError_BackPattern
Definition omError.h:38
omError_NullAddr
@ omError_NullAddr
Definition omError.h:22
omError_NullSizeAlloc
@ omError_NullSizeAlloc
Definition omError.h:33
omError_MaxError
@ omError_MaxError
Definition omError.h:42
omError_FrontPattern
@ omError_FrontPattern
Definition omError.h:39
omError_UnalignedAddr
@ omError_UnalignedAddr
Definition omError.h:32
omError_MemoryCorrupted
@ omError_MemoryCorrupted
Definition omError.h:21
omError_FreedAddr
@ omError_FreedAddr
Definition omError.h:27
omError_UnknownBin
@ omError_UnknownBin
Definition omError.h:30
omError_FreedAddrOrMemoryCorrupted
@ omError_FreedAddrOrMemoryCorrupted
Definition omError.h:28
omError_NotString
@ omError_NotString
Definition omError.h:40
omError_SortedListError
@ omError_SortedListError
Definition omError.h:35
omError_KeptAddrListCorrupted
@ omError_KeptAddrListCorrupted
Definition omError.h:36
omError_InternalBug
@ omError_InternalBug
Definition omError.h:20
omError_NotBinAddr
@ omError_NotBinAddr
Definition omError.h:31
omError_InvalidRangeAddr
@ omError_InvalidRangeAddr
Definition omError.h:23
omError_FalseAddr
@ omError_FalseAddr
Definition omError.h:24
omError_WrongBin
@ omError_WrongBin
Definition omError.h:29
omError_NoError
@ omError_NoError
Definition omError.h:18
omError_Unknown
@ omError_Unknown
Definition omError.h:19
omError_StickyBin
@ omError_StickyBin
Definition omError.h:41
omError_FreePattern
@ omError_FreePattern
Definition omError.h:37
omError_FalseAddrOrMemoryCorrupted
@ omError_FalseAddrOrMemoryCorrupted
Definition omError.h:25
NULL
#define NULL
Definition omList.c:12
om_Opts
omOpts_t om_Opts
Definition omOpts.c:13
om_Info
omInfo_t om_Info
Definition omStats.c:16
omBin
omBin_t * omBin
Definition omStructs.h:12
om_sing_opt_show_mem
int om_sing_opt_show_mem
A
#define A
Definition sirandom.c:24
omInfo_s::UsedBytesMalloc
long UsedBytesMalloc
Definition omStats.h:20
omOpts_s::MinCheck
int MinCheck
Definition omOpts.h:14
omInfo_s::CurrentBytesFromValloc
long CurrentBytesFromValloc
Definition omStats.h:26
omBin_s::size
size_t size
Definition xalloc.h:120
omOpts_s::MemoryLowFunc
void(* MemoryLowFunc)(void)
Definition omOpts.h:22
omFree
#define omFree(d)
Definition xalloc.h:104
omInfo_s::CurrentBytesFromMalloc
long CurrentBytesFromMalloc
Definition omStats.h:24
omOpts_s::Keep
int Keep
Definition omOpts.h:17
omInfo_s::AvailBytesMalloc
long AvailBytesMalloc
Definition omStats.h:22
omBin_next_s::next
omBin_next next
Definition xalloc.h:114
omInfo_s::CurrentBytesMmap
long CurrentBytesMmap
Definition omStats.h:17
omInfo_s::AvailPages
long AvailPages
Definition omStats.h:31
omOpts_s::MinTrack
int MinTrack
Definition omOpts.h:13
omInfo_s::CurrentRegionsAlloc
long CurrentRegionsAlloc
Definition omStats.h:33
omBin_s::curr
omBin_next curr
Definition xalloc.h:119
omInfo_s::UsedBytesFromValloc
long UsedBytesFromValloc
Definition omStats.h:27
omBin_next
omBin_next_t * omBin_next
Definition xalloc.h:111
omInfo_s::MaxBytesFromValloc
long MaxBytesFromValloc
Definition omStats.h:25
omInfo_s::MaxPages
long MaxPages
Definition omStats.h:29
omAlloc
#define omAlloc(s)
Definition xalloc.h:85
omOpts_s::HowToReportErrors
int HowToReportErrors
Definition omOpts.h:18
omInfo_s::CurrentBytesSystem
long CurrentBytesSystem
Definition omStats.h:13
omOpts_s::MarkAsStatic
int MarkAsStatic
Definition omOpts.h:19
omOpts_s::OutOfMemoryFunc
void(* OutOfMemoryFunc)(void)
Definition omOpts.h:21
omInfo_s::AvailBytesFromValloc
long AvailBytesFromValloc
Definition omStats.h:28
omInfo_s::MaxBytesSbrk
long MaxBytesSbrk
Definition omStats.h:14
omOpts_s::MaxTrack
int MaxTrack
Definition omOpts.h:15
omInfo_s::MaxRegionsAlloc
long MaxRegionsAlloc
Definition omStats.h:32
omInfo_s::UsedPages
long UsedPages
Definition omStats.h:30
omOpts_s::PagesPerRegion
unsigned int PagesPerRegion
Definition omOpts.h:20
omInfo_s::UsedBytes
long UsedBytes
Definition omStats.h:18
omInfo_s::MaxBytesFromMalloc
long MaxBytesFromMalloc
Definition omStats.h:23
omInfo_s::CurrentBytesSbrk
long CurrentBytesSbrk
Definition omStats.h:15
omInfo_s::MaxBytesMmap
long MaxBytesMmap
Definition omStats.h:16
omInfo_s::MaxBytesSystem
long MaxBytesSystem
Definition omStats.h:12
omInfo_s::AvailBytes
long AvailBytes
Definition omStats.h:19
omOpts_s::ErrorHook
void(* ErrorHook)(void)
Definition omOpts.h:23
omOpts_s::MaxCheck
int MaxCheck
Definition omOpts.h:16
omBin_next_s
Definition xalloc.h:113
omBin_s
Definition omAllocPrivate.h:37
omInfo_s
Definition omStats.h:11
omOpts_s
Definition omOpts.h:12