source: git/Singular/mmalloc.c @ 18dd47

spielwiese
Last change on this file since 18dd47 was 32df82, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: removed rcsid and Log: entries, added assignment module=poly corected type conversion int->module git-svn-id: file:///usr/local/Singular/svn/trunk@128 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 1.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: mmalloc.c,v 1.2 1997-04-02 15:07:28 Singular Exp $ */
5
6/*
7* ABSTRACT:
8*/
9
10#define _POSIX_SOURCE 1
11
12#include <string.h>
13#include <stdlib.h>
14#include <stdio.h>
15#include "mod2.h"
16#include "tok.h"
17#include "structs.h"
18#include "mmemory.h"
19#include "mmprivat.h"
20
21size_t mmSizeL( void* adr )
22{
23  if (adr!=NULL)
24  {
25    adr = (size_t*)adr-1;
26    return *(size_t*)adr;
27  }
28  return 0;
29}
30
31#ifndef MDEBUG
32
33void * mmAlloc( size_t size )
34{
35  size_t thesize = size + sizeof( ADDRESS );
36  size_t * dummy = (size_t*)mmAllocBlock( thesize );
37  *dummy = thesize;
38  return (void*)(dummy+1);
39}
40
41void mmFree( void* adr )
42{
43  if (adr!=NULL)
44  {
45    adr = (size_t*)adr-1;
46    mmFreeBlock( adr, *(size_t*)adr );
47  }
48}
49
50void * mmRealloc( void* adr, size_t newsize )
51{
52  size_t *aadr=(size_t*)(adr)-1;
53  size_t oldsize = *aadr;
54  void* newadr = mmAlloc( newsize );
55  memcpy( newadr, adr, min(oldsize-sizeof(ADDRESS),newsize) );
56  mmFreeBlock( aadr,oldsize );
57  return newadr;
58}
59
60#else /* MDEBUG */
61
62void * mmDBAlloc( size_t size, char* fname, int lineno )
63{
64  size_t thesize = size + sizeof( ADDRESS );
65  size_t * dummy = (size_t*)mmDBAllocBlock( thesize, fname, lineno );
66  *dummy = thesize;
67  return (void*)(dummy+1);
68}
69
70void mmDBFree( void* adr, char* fname, int lineno )
71{
72  if (adr!=NULL)
73  {
74    adr = (size_t*)adr-1;
75    mmDBFreeBlock( adr,*(size_t *)adr, fname, lineno );
76  }
77}
78
79void * mmDBRealloc( void* adr, size_t newsize, char* fname, int lineno )
80{
81  size_t *aadr=(size_t*)(adr)-1;
82  size_t oldsize = *aadr;
83  void* newadr = mmDBAlloc( newsize, fname, lineno );
84  memcpy( newadr, adr, min(oldsize-sizeof(ADDRESS), newsize) );
85  mmDBFreeBlock( aadr, oldsize, fname, lineno );
86  return newadr;
87}
88
89#endif /* MDEBUG */
Note: See TracBrowser for help on using the repository browser.