Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.apple2.programmer > #4107 > unrolled thread
| Started by | Chris Vavruska <vavruska@gmail.com> |
|---|---|
| First post | 2018-01-16 06:26 -0800 |
| Last post | 2018-01-16 17:39 -0600 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.sys.apple2.programmer
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
| From | Chris Vavruska <vavruska@gmail.com> |
|---|---|
| Date | 2018-01-16 06:26 -0800 |
| Subject | orca/c NewHandle vs malloc |
| Message-ID | <128c4512-aa51-4fe3-91d1-30b8d09647f2@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Stephen Heumann <stephen.heumann@gmail.com> |
|---|---|
| Date | 2018-01-16 17:39 -0600 |
| Message-ID | <p3m2eq$uhd$1@dont-email.me> |
| In reply to | #4107 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.sys.apple2.programmer
csiph-web