Mail Archives: djgpp/1996/10/29/23:33:51
In article <552sj1$ge3 AT sun-cc204 DOT lboro DOT ac DOT uk>, cgjks1 AT lut DOT ac DOT uk (James Soutter) writes:
|>Ulrich Lauther (lauther AT cayley DOT zfe DOT siemens DOT de) wrote:
|>: James Soutter (cgjks1 AT lut DOT ac DOT uk) wrote:
|>: :
|>: : Excuse my ignorance by why use sbrk(). I thought changing sbrk() was a
|>: : bad idea because it broke the library functions that called malloc().
|>: :
|>: you didn't read my question. I need it under Visual C++ (which I am
|>: *forced* to use). I cannot use malloc (at least not conveniently) as
|>: I need memory aligned to 4096 byte boundaries.
|>
Using a simple wrapper to malloc can achieve this, at the cost of
wasting memory - simply allocate what you want + 4096, and pick the
chunk which is 4096-byte aligned.
|>My question was really about the use of sbrk() rather than your
|>particular situation.
|>
|>
[ snip ]
||>
|>Does sbrk() work on all UNIX operating systems? I have always been
|>scared off by the SunOS Manual on sbrk() [quoted below].
sbrk() _works_ on all systems. The warning you quote doesn't say
otherwise. The problem is that sbrk() is a primitive, low-level interface
for expanding your address space, and it only works effectively if
all its callers cooperate with each other, or at least understand each
other's behaviour. standard malloc() assumes it is the sole user of sbrk().
It breaks if this is not the case. You have three courses of action that
I can see:
(1) Give up on sbrk() and find a way to use malloc to do what you want.
(2) Use sbrk() and make sure you do not call any library routines that
use malloc. The only way to be sure is to look at what routines
get loaded into the final executable. This course of action may be
impossible, since malloc() is used so much by standard library
routines.
(3) Write your own replacement malloc() which co-exists with your use
of sbrk(). Probably easier than (2), if (1) is a non-starter.
-----------------------------------------------------------------------------
Kevin Ashley K DOT Ashley AT Ulcc DOT ac DOT uk
Development Manager http://www.ulcc.ac.uk/staff/Kevin+Ashley
University of London Computer Centre. ...ukc!ncdlab!K.Ashley
This is not a signature
- Raw text -