implementing dataWithContentsOfMemory as NSData category
implementing dataWithContentsOfMemory as NSData category
- Subject: implementing dataWithContentsOfMemory as NSData category
- From: Mike Bolton <email@hidden>
- Date: Wed, 15 Sep 2004 22:25:56 -0400 (EDT)
First off, just wanted to say thanks to those that
answered my previous question, I really appreciate it.
I now have a question regarding NSData. At the
moment, I use an NSData object and
dataWIthContentsOfMappedFile to map a file from disk
to memory so that I can parse the contents. The
problem is that I also need to be able to parse these
files while they're in memory (in another task). I
was thinking of extending NSData by adding my own
category to implement a method such as:
+ (NSData *) dataWithContentsOfMemory:(const void
*)addr size:(unsigned long)size
task:(task_t)target_task;
and then in the actual method itself, I'd use
something like vm_map to map the memory to addr. The
question is, how do I then create an NSData object to
wrap around this address. I was thinking of using: "+
[NSData dataWithBytesNoCopy:(void *)bytes
length:(unsigned)length]", but it states in the
documentation that "bytes must point to a memory block
allocated with malloc.", so I'm not sure if this will
work. And using "+ [NSData dataWithBytes:(const void
*)bytes length:(unsigned)length]", will cause the
entire chunk of memory to be copied, which is not what
I want either. So what I'm wondering is if there's a
way to create an NSData object that represents
vm_map'd memory, given that none of the methods
available in the NSData class provide this
functionality (unless I'm missing something).
I've started thinking that I should probably just
abandon NSData altogether, and use map_fd/mmap
(instead of dataWIthContentsOfMappedFile ) and vm_map
(for mapping from memory). But of course I'm still
very curious as to how one would implement this using
an NSData category. If anyone has any suggestions or
comments, please let me know your thoughts. Thanks,
Mike
______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden