garyb@tekcrl.LABS.TEK.COM (Gary Beaver) (07/06/89)
I've been trying to implement an XFCN in MPW 2.0 C which invokes the function, malloc. I've tried this using two different naming conventions. In the first method, when the XFCN is named "foo" [all segments names are changed using the -sn option; link is invoked with the option "-m foo"], the linker doesn't tolerate the malloc call, reporting something to the effect, "data initialization code not called"; without malloc, linking successfully runs to completion. In the second method, when the XFCN is named "main", the linker successfully creates not one but two resources within the target file, one which I expect named "main" and one which I don't expect named "%A5Init". The resulting "main" resource doesn't not work properly. From my limited vantage point, I suspect that in this case, the use of malloc implicitly creates some global variables, violating the rules for XFCNs and XCMDs. In either case, I haven't found a way to get this XFCN to work, and I definitely need to allocate memory dynamically. What's going on here? Is it possible to create an XFCN which dynamically allocates memory with the standard library function, malloc? If not, are there any relatively simple workarounds? Thanks in advance.
amanda@intercon.uu.net (Amanda Walker) (07/06/89)
In article <4256@tekcrl.LABS.TEK.COM>, garyb@tekcrl.LABS.TEK.COM (Gary Beaver) writes: > Is it possible to create an XFCN which dynamically > allocates memory with the standard library function, malloc? If not, are > there any relatively simple workarounds? The simplest thing is probably to use the Memory Manager directly. The calls that are closest to malloc() and free() are NewPtr() and DisposPtr(). -- Amanda Walker InterCon Systems Corporation amanda@intercon.uu.net | ...!uunet!intercon!amanda