source: git/Singular/mmalloc.c @ c9567bf

spielwiese
Last change on this file since c9567bf was c9567bf, checked in by Hans Schönemann <hannes@…>, 26 years ago
* hannes: bug fixes to TEST_MAC_ORDER (binom.cc binom.h polys-impl.h spSpolyLoop.cc) git-svn-id: file:///usr/local/Singular/svn/trunk@1062 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: mmalloc.c,v 1.5 1998-01-24 17:22:06 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 */
90
91#ifdef DO_DEEP_PROFILE
92void _memcpyW(void* p1, void* p2, long l)
93{
94  long _i = l;                                 
95  long* _s1 = (long*) p1;                       
96  const long* _s2 = (long*) p2;                 
97                                               
98  for (;;)                                     
99  {                                             
100    *_s1 = *_s2;                               
101    _i--;                                       
102    if (_i == 0) break;                         
103    _s1++;                                     
104    _s2++;                                     
105  }                                             
106}                                               
107#endif 
108
Note: See TracBrowser for help on using the repository browser.