• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSData object trouble with <16KB
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData object trouble with <16KB


  • Subject: Re: NSData object trouble with <16KB
  • From: "David Piasecki" <email@hidden>
  • Date: Thu, 22 Apr 2004 15:04:36 -0700

Thanks. That makes more sense now. I had previously assumed (coming from the C++/Java world) that alloc created a new object and init or initFoo simply called different constructors.

David


On Apr 22, 2004, at 3:04 PM, Bob Ippolito wrote:

It's not really strange per se.. alloc and init are allowed to return different objects. If init can return several different kinds of instances, then you have what is called a class cluster. NSData is one of these class clusters, and it just so happens that NSData proper is the particular class in the cluster that is used when there is more than 16k of data.

If you were to use different lines, you would do:
NSData *data = [NSData alloc];
data = [data initWithBytes:getData() length:getDataLength()];

For the same reason, you also do things like this pretty often when subclassing:
self = [super init];

Even though you already had a self, previously.

-bob

On Apr 22, 2004, at 5:24 PM, David Piasecki wrote:

Thanks! That was indeed my problem. Being new to Objective-C, I tend to run into these problems. Strange that it only happened on small data sizes and not the big ones.

Thanks again,
David


On Apr 22, 2004, at 2:14 PM, Ondra Cada wrote:

David,

On 22.4.2004, at 22:47, David Piasecki wrote:

NSData *data = [NSData alloc];
[data initWithBytes:getData() length:getDataLength()];

getData() returns a char *
getDataLength() returns an int

The "data" ends up being of size 0 bytes. If the size of the data I
pass in is greater than 16KB, there is no problem. Unfortunately, I may
have data sizes smaller than 16KB. Has anyone ran into this problem,
and do you know of some way around it, or perhaps I'm doing something
wrong?

*NEVER EVER* separate alloc and init to two different lines. That's the culprit -- init returns a different object (which it can do any time, and for class clusters it of course does indeed).
---
Ondra D ada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.
_______________________________________________
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.


  • Follow-Ups:
    • Re: NSData object trouble with <16KB
      • From: Michael Hall <email@hidden>
    • Re: NSData object trouble with <16KB
      • From: Ondra Cada <email@hidden>
References: 
 >NSData object trouble with <16KB (From: "David Piasecki" <email@hidden>)
 >Re: NSData object trouble with <16KB (From: Ondra Cada <email@hidden>)
 >Re: NSData object trouble with <16KB (From: "David Piasecki" <email@hidden>)
 >Re: NSData object trouble with <16KB (From: Bob Ippolito <email@hidden>)

  • Prev by Date: Re: NSData object trouble with <16KB
  • Next by Date: Re: NSData object trouble with <16KB
  • Previous by thread: Re: NSData object trouble with <16KB
  • Next by thread: Re: NSData object trouble with <16KB
  • Index(es):
    • Date
    • Thread