> Anyone have any quick code to retrieve the number of bytes in a string
> /without/ writing the string to a file first?  I'm trying to do a
> little debugging and I'd like to know the size of a string that is
> being returned to the browser.

The number of bytes occupied in the application's memory by the Java String
object is probably not the same as the number of bytes occupied by the same
string in the HTTP response.

I could be wrong on some points below but I'm sure others will correct me if
so (Paul?)

As I understand it, a Java program such as CF always stores characters
internally using UCS-2 encoding, i.e. 2 bytes per character. In addition,
the String object will include 20 or 30 extra bytes for storing the length
of the string etc.

I believe that CF's default behaviour is to encode HTTP responses using
UTF-8 encoding, i.e. 1 byte per character if you're only using ASCII
characters, and of course the extra bytes used by the String object won't be
there either.

So let's say your string is "Rob".

- In CF the Len() function gives you 3.

- The size of the Java object - even if you could work it out, which is next
to impossible in Java - would be 6 + the extra bytes, maybe 40 or more.

- But in the HTTP response it would probably be 3.

So, if I've understood your question correctly and it's the HTTP response
you're interested in, just using Len() in CF will give you the best answer.

Nick





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238125
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to