Memory management for bridging code
Memory management for bridging code
- Subject: Memory management for bridging code
- From: Wade Tregaskis <email@hidden>
- Date: Fri, 23 May 2003 10:36:22 +1000
I'm writing an ObjC wrapper for a C library (CDSA), and making good
progress for the most part. I'm having headaches with memory
management, though. For example, here's a common problem:
a) Start with a C struct or pointer-to from the CDSA or some other
source
b) Instantiate one of my classes around this structure, referring to it
by a pointer
c) Original structure is deallocated by CDSA or other code outside my
control
d) Instance previously created no longer valid; leads to a seg fault if
used
One fix for the above is to make internal copies of every basic C data
structure at instantiation; then my class can control when the raw data
gets thrown out (i.e. in it's own dealloc method). But that introduces
the overhead of copying C structs all the time, plus it's very static -
if I create an instance around a struct, and then change the struct,
the class doesn't reflect the changes.
Is there a way to have the best of both worlds - dynamism and not
crashing? To be honest I don't think the static approach will be too
detrimental in practice, but I'm wondering if there's a simple approach
to problems like this in general.
Wade Tregaskis
-- Sed quis custodiet ipsos custodes?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.