source: git/factory/mmalloc.c @ 276c3f

spielwiese
Last change on this file since 276c3f was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* emacs edit mode for this file is -*- C -*- */
2/* $Id$ */
3
4#define _POSIX_SOURCE 1
5
6#include <config.h>
7
8#include <string.h>
9#include <stdlib.h>
10
11#include "memman.h"
12#include "mmprivate.h"
13
14size_t
15mmSizeL( void* adr )
16{
17    if (adr!=NULL) {
18
19        adr = (size_t*)adr-1;
20        return *(size_t*)adr;
21    }
22    return 0;
23}
24
25#ifndef MDEBUG
26
27void *
28mmAlloc( size_t size )
29{
30    size_t thesize = size + sizeof( void * );
31    size_t * dummy = (size_t*)mmAllocBlock( thesize );
32    *dummy = thesize;
33    return (void*)(dummy+1);
34}
35
36void
37mmFree( void* adr )
38{
39    if (adr!=NULL) {
40        adr = (size_t*)adr-1;
41        mmFreeBlock( adr, *(size_t*)adr );
42    }
43}
44
45void *
46mmRealloc( void* adr, size_t newsize )
47{
48    size_t oldsize = *((size_t*)(adr)-1);
49    void* newadr = mmAlloc( newsize );
50    memcpy( newadr, adr, (oldsize < newsize) ? oldsize : newsize );
51    mmFree( adr );
52    return newadr;
53}
54
55#else /* MDEBUG */
56
57void *
58mmDBAlloc( size_t size, char* fname, int lineno )
59{
60    size_t thesize = size + sizeof( void * );
61    size_t * dummy = (size_t*)mmDBAllocBlock( thesize, fname, lineno );
62    *dummy = thesize;
63    return (void*)(dummy+1);
64}
65
66void
67mmDBFree( void* adr, char* fname, int lineno )
68{
69    if (adr!=NULL) {
70        size_t l;
71        adr = (size_t*)adr-1;
72#ifdef __alpha__
73        l= (*(size_t*)((int)adr&(~7)));
74#else
75        l= (*(size_t*)((int)adr&(~3)));
76#endif
77        mmDBFreeBlock( adr,l, fname, lineno );
78    }
79}
80
81void *
82mmDBRealloc( void* adr, size_t newsize, char* fname, int lineno )
83{
84    size_t oldsize = *((size_t*)(adr)-1);
85    void* newadr = mmDBAlloc( newsize, fname, lineno );
86    memcpy( newadr, adr, (oldsize < newsize) ? oldsize : newsize );
87    mmDBFree( adr, fname, lineno );
88    return newadr;
89}
90
91#endif /* MDEBUG */
Note: See TracBrowser for help on using the repository browser.