What is the size/length of NSString data type in objective c?
Asked
Active
Viewed 249 times
-1
-
2`NSString` data type? The pointer? The content? In bytes? Why? – Wain Feb 06 '14 at 11:12
-
http://stackoverflow.com/questions/6482641/what-is-the-maximum-length-of-an-nsstring-object – Sachin Feb 06 '14 at 11:12
-
why indeed. it depends on the string I'd say, Cocoa uses a bunch of private string classes for various purposes. – Stefan Fisk Feb 06 '14 at 11:12
-
Yes in bytes. My senior in the company has told me to find out, i tried googling it out but did not find any answer for it. I guess it is 4 or 8 bytes but i am not sure. – user3202087 Feb 06 '14 at 11:13
-
hey friend i think this one is duplicate of this question http://stackoverflow.com/questions/6482641/what-is-the-maximum-length-of-an-nsstring-object – freelancer Feb 06 '14 at 11:15
-
this might help: http://stackoverflow.com/a/762041/653513 your senior has some strange requests though ;) – Rok Jarc Feb 06 '14 at 11:15
-
4Ask him why you should find that out. To answer this question you need more context. If it's for storing or transfering data you are actually not interested in NSString. You want to know about its representation in UTF-8 or UTF-16 or whatever. I can't imagine a single case where you would be interested in the byte size (whatever this means) of a NSString. – Matthias Bauch Feb 06 '14 at 11:18
-
@MatthiasBauch why do u even think about UTF-16 or 8 if the question about its layout in memory, Keyword here is a TYPE NSString not its instance. In other words, if somebody wanted to allocate space for 1 NSString object how many bytes he would need. The reason behind it ? well maybe I just wanna copy an object to a more comfortable memory region. – Anton Stafeyev Oct 18 '20 at 08:57
1 Answers
-1
Size of all pointer type is 4 bytes in 32-bit processor. 8 bytes for 64-bit processor. NSString*
belonging to pointer type, so size of NSString*
data type is depends on pointer type(above). See this apple's doc

Mani
- 17,549
- 13
- 79
- 100
-
This is very misleading answer, author is talking about the size of NSString type, which you could resolve with sizeof() for c types but it doesn't work with objective-c, and since apple has moved to 64 bit platform and ditched 32bit your answer is even more misleading. – Anton Stafeyev Oct 18 '20 at 08:59