X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fnmem.c;h=1f8824f30076606851b169d8ba640502d6712c81;hb=5c3d2d2ab097e4bb59ba5718a396b020a2d302c0;hp=37de136f58468a1aa51909fa6ac9437dc695918d;hpb=130c4f389f6e2166f533beb831e991f806130f72;p=yaz-moved-to-github.git diff --git a/src/nmem.c b/src/nmem.c index 37de136..1f8824f 100644 --- a/src/nmem.c +++ b/src/nmem.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 1995-2004, Index Data. + * Copyright (c) 1995-2005, Index Data. * See the file LICENSE for details. * - * $Id: nmem.c,v 1.8 2004-12-16 08:59:36 adam Exp $ + * $Id: nmem.c,v 1.11 2005-01-05 10:23:42 adam Exp $ */ /** @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,23 @@ #define NMEM_CHUNK (4*1024) +struct align { + char x; + union { + char c; + short s; + int i; + long l; +#if HAVE_LONG_LONG + long long ll; +#endif + float f; + double d; + } u; +}; + +#define NMEM_ALIGN (offsetof(struct align, u)) + static int log_level=0; static int log_level_initialized=0; @@ -266,7 +284,7 @@ void *nmem_malloc(NMEM n, int size) } r = p->buf + p->top; /* align size */ - p->top += (size + (sizeof(long) - 1)) & ~(sizeof(long) - 1); + p->top += (size + (NMEM_ALIGN - 1)) & ~(NMEM_ALIGN - 1); n->total += size; NMEM_LEAVE; return r;