Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #4108

Re: orca/c NewHandle vs malloc

From Stephen Heumann <stephen.heumann@gmail.com>
Newsgroups comp.sys.apple2.programmer
Subject Re: orca/c NewHandle vs malloc
Date 2018-01-16 17:39 -0600
Organization A noiseless patient Spider
Message-ID <p3m2eq$uhd$1@dont-email.me> (permalink)
References <128c4512-aa51-4fe3-91d1-30b8d09647f2@googlegroups.com>

Show all headers | View raw


On 2018-01-16 14:26:41 +0000, Chris Vavruska said:

> When writing a GS/OS finder extension is there any difference between 
> allocating memory with NewHandle vs malloc other that the features that 
> MM includes (locking the memory, etc).  From what I understand (a 
> memory from years ago) is that the orcaLib uses NewHandle to alloc a 
> block of memory and then divides it up as needed based on memory 
> malloc'd. I use a lot of mallocs in my code and am seeing odd memory 
> corruptions that cause the system to crash that I have yet to find and 
> thought it might have something to do with my use of malloc.

In general, I'm not aware of any reason that malloc should cause 
problems.  You do need to be sure that the ORCA libraries are 
initialized with the proper UserID, which malloc will use when calling 
NewHandle.  If you start up straight into C code using an 
ORCA/C-generated .root file then this should be handled correctly for 
you, but if you're calling ORCA/C code from something that starts in 
assembly then you'll need to handle it yourself (call SystemUserID, 
plus any other functions needed to initialize parts of the libraries 
that you're using).

You're right that (for small allocations) malloc will use NewHandle to 
allocate a larger block and then divide it up as needed.  For 
allocations of 4KB or larger it will always call NewHandle.  If you 
have the library sources, you can see the allocator code in mm.asm 
(part of SysLib).

-- 
Stephen Heumann

Back to comp.sys.apple2.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

orca/c NewHandle vs malloc Chris Vavruska <vavruska@gmail.com> - 2018-01-16 06:26 -0800
  Re: orca/c NewHandle vs malloc Stephen Heumann <stephen.heumann@gmail.com> - 2018-01-16 17:39 -0600

csiph-web