Logo ROOT  
Reference Guide
sbrksup.c
Go to the documentation of this file.
1/* @(#)root/clib:$Id$ */
2/* Author: */
3
4/* Support for sbrk() regions.
5 Copyright 1992 Free Software Foundation, Inc.
6 Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com
7
8This file is part of the GNU C Library.
9
10The GNU C Library is free software; you can redistribute it and/or
11modify it under the terms of the GNU Library General Public License as
12published by the Free Software Foundation; either version 2 of the
13License, or (at your option) any later version.
14
15The GNU C Library is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18Library General Public License for more details.
19
20You should have received a copy of the GNU Library General Public
21License along with the GNU C Library; see the file COPYING.LIB. If
22not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23Boston, MA 02111-1307, USA. */
24
25#include <string.h> /* Prototypes for memcpy, memmove, memset, etc */
26
27#include "mmprivate.h"
28
29#ifndef NO_SBRK_MALLOC
30
31extern PTR sbrk ();
32
33/* The mmalloc() package can use a single implicit malloc descriptor
34 for mmalloc/mrealloc/mfree operations which do not supply an explicit
35 descriptor. For these operations, sbrk() is used to obtain more core
36 from the system, or return core. This allows mmalloc() to provide
37 backwards compatibility with the non-mmap'd version. */
38
40
41/* Use sbrk() to get more core. */
42
43static PTR
45 struct mdesc *mdp;
46 int size;
47{
48 PTR result;
49
50 if ((result = sbrk (size)) == (PTR) -1)
51 {
52 result = NULL;
53 }
54 else
55 {
56 mdp -> breakval += size;
57 mdp -> top += size;
58 }
59 return (result);
60}
61
62/* Initialize the default malloc descriptor if this is the first time
63 a request has been made to use the default sbrk'd region.
64
65 Since no alignment guarantees are made about the initial value returned
66 by sbrk, test the initial value and (if necessary) sbrk enough additional
67 memory to start off with alignment to BLOCKSIZE. We actually only need
68 it aligned to an alignment suitable for any object, so this is overkill.
69 But at most it wastes just part of one BLOCKSIZE chunk of memory and
70 minimizes portability problems by avoiding us having to figure out
71 what the actual minimal alignment is. The rest of the malloc code
72 avoids this as well, by always aligning to the minimum of the requested
73 size rounded up to a power of two, or to BLOCKSIZE.
74
75 Note that we are going to use some memory starting at this initial sbrk
76 address for the sbrk region malloc descriptor, which is a struct, so the
77 base address must be suitably aligned. */
78
79struct mdesc *
81{
82 PTR base;
83 unsigned int adj;
84
85 base = sbrk (0);
86 adj = RESIDUAL (base, BLOCKSIZE);
87 if (adj != 0)
88 {
89 sbrk (BLOCKSIZE - adj);
90 base = sbrk (0);
91 }
92 __mmalloc_default_mdp = (struct mdesc *) sbrk (sizeof (struct mdesc));
93 memset ((char *) __mmalloc_default_mdp, 0, sizeof (struct mdesc));
98 return (__mmalloc_default_mdp);
99}
100
101#endif /* NO_SBRK_MALLOC */
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
#define NULL
Definition ZInflate.c:15
static PTR morecore(struct mdesc *mdp, size_t size)
Definition mmalloc.c:81
#define PTR
Definition mmalloc.h:29
#define RESIDUAL(addr, bsize)
Definition mmprivate.h:85
struct mdesc * __mmalloc_default_mdp
Definition sbrksup.c:39
#define BLOCKSIZE
Definition mmprivate.h:81
struct mdesc * __mmalloc_sbrk_init()
Definition sbrksup.c:80
static PTR sbrk_morecore(struct mdesc *mdp, int size)
Definition sbrksup.c:44
PTR sbrk()
int fd
Definition mmprivate.h:307
char * base
Definition mmprivate.h:284
char * top
Definition mmprivate.h:294
char * breakval
Definition mmprivate.h:289