RE: Get String Byte Size
I thought java stored all strings as double-byte unicode. Is this incorrect? That would make it len(string) * 16 Leon -Original Message- From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] Sent: Thursday, April 20, 2006 9:13 AM To: CF-Talk Subject: RE: Get String Byte Size Oops yes, / 8 The OS and cluster sizes may also make a difference ;-) ...:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Loathe [mailto:[EMAIL PROTECTED] Sent: Thursday, April 20, 2006 10:05 AM To: CF-Talk Subject: RE: Get String Byte Size Or len(string) * 8? Isn't each ascii character one byte? Or is it one bit? And it it is wouldn't just be len(string) / 8? -- Timothy Heald Analyst, Architect, Developer [EMAIL PROTECTED] W: 202-228-8372 C: 703-300-3911 -Original Message- From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] Sent: Thursday, April 20, 2006 10:00 AM To: CF-Talk Subject: RE: Get String Byte Size Wouldn't that just be len(string) ? .:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238352 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
RE: Get String Byte Size
Try this: http://martin.nobilitas.com/java/sizeof.html The empirical formula derived there indicates that string memory is 38+/-2 + 2*(string length) bytes. In my own tests on JDK 1.4.2_09 I got something similar: 40 + 2*(string length) bytes when length2. For length 0 to 2, the size works out to just 40 bytes. That said, as Nick mentions, if all that you're trying to do is get an idea of the relative memory occupied by different strings, rather than the actual physical memory (which, as discussed in the link above, can be determined only empirically, not precisely), you might be best off just checking the length. -Original Message- From: Nick de Voil [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:47 PM To: CF-Talk Subject: Re: Get String Byte Size 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:238247 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
Re: Get String Byte Size
Thanks, all. These suggestions will get me close enough for what I need. Fortunately, this data isn't required for anything essential. I appreciate all the help. On 4/20/06, Ashwin Mathew [EMAIL PROTECTED] wrote: Try this: http://martin.nobilitas.com/java/sizeof.html The empirical formula derived there indicates that string memory is 38+/-2 + 2*(string length) bytes. In my own tests on JDK 1.4.2_09 I got something similar: 40 + 2*(string length) bytes when length2. For length 0 to 2, the size works out to just 40 bytes. That said, as Nick mentions, if all that you're trying to do is get an idea of the relative memory occupied by different strings, rather than the actual physical memory (which, as discussed in the link above, can be determined only empirically, not precisely), you might be best off just checking the length. -Original Message- From: Nick de Voil [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:47 PM To: CF-Talk Subject: Re: Get String Byte Size 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:238250 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=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: Get String Byte Size
Wouldn't that just be len(string) ? ..:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238270 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=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: Get String Byte Size
Or len(string) * 8? Isn't each ascii character one byte? Or is it one bit? And it it is wouldn't just be len(string) / 8? -- Timothy Heald Analyst, Architect, Developer [EMAIL PROTECTED] W: 202-228-8372 C: 703-300-3911 -Original Message- From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] Sent: Thursday, April 20, 2006 10:00 AM To: CF-Talk Subject: RE: Get String Byte Size Wouldn't that just be len(string) ? ...:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238271 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
RE: Get String Byte Size
That just returns the number of characters, not the file size those characters would have. !//-- andy matthews web developer ICGLink, Inc. [EMAIL PROTECTED] 615.370.1530 x737 --//- -Original Message- From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] Sent: Thursday, April 20, 2006 9:00 AM To: CF-Talk Subject: RE: Get String Byte Size Wouldn't that just be len(string) ? ...:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238273 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
RE: Get String Byte Size
Oops yes, / 8 The OS and cluster sizes may also make a difference ;-) ..:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Loathe [mailto:[EMAIL PROTECTED] Sent: Thursday, April 20, 2006 10:05 AM To: CF-Talk Subject: RE: Get String Byte Size Or len(string) * 8? Isn't each ascii character one byte? Or is it one bit? And it it is wouldn't just be len(string) / 8? -- Timothy Heald Analyst, Architect, Developer [EMAIL PROTECTED] W: 202-228-8372 C: 703-300-3911 -Original Message- From: Bobby Hartsfield [mailto:[EMAIL PROTECTED] Sent: Thursday, April 20, 2006 10:00 AM To: CF-Talk Subject: RE: Get String Byte Size Wouldn't that just be len(string) ? :.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238277 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=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Get String Byte Size
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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238076 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
RE: Get String Byte Size
Rob, Characters take up one byte... As far as I know... Althoug unicode may take up 4?? I can't remember. I suppose the best estimate would be to multiply the string length by the byte size of each characters: intSizeEstimate = Len( strFileContent ) * 4 -b ... Ben Nadel Web Developer Nylon Technology 350 7th Ave. Suite 1005 New York, NY 10001 212.691.1134 x 14 212.691.3477 fax www.nylontechnology.com Sanders: Lightspeed too slow? Helmet: Yes we'll have to go right to ludacris speed. -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238079 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=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: Get String Byte Size
And therein lies the key. I may - or may not - have unicode involved. I was hoping someone knew of some quick java to return the byte size of a string that would handle those vagaries. I haven't found anything in my searches. On 4/19/06, Ben Nadel [EMAIL PROTECTED] wrote: Rob, Characters take up one byte... As far as I know... Althoug unicode may take up 4?? I can't remember. I suppose the best estimate would be to multiply the string length by the byte size of each characters: intSizeEstimate = Len( strFileContent ) * 4 -b ... Ben Nadel Web Developer Nylon Technology 350 7th Ave. Suite 1005 New York, NY 10001 212.691.1134 x 14 212.691.3477 fax www.nylontechnology.com Sanders: Lightspeed too slow? Helmet: Yes we'll have to go right to ludacris speed. -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238082 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
RE: Get String Byte Size
I would think that at the Java level there would be some way to get the size of a variable. Maybe these might help?: http://www.roseindia.net/javatutorials/determining_memory_usage_in_java.shtm l http://gcc.gnu.org/ml/java/2003-02/msg00293.html !//-- andy matthews web developer ICGLink, Inc. [EMAIL PROTECTED] 615.370.1530 x737 --//- -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 8:57 AM To: CF-Talk Subject: Re: Get String Byte Size And therein lies the key. I may - or may not - have unicode involved. I was hoping someone knew of some quick java to return the byte size of a string that would handle those vagaries. I haven't found anything in my searches. On 4/19/06, Ben Nadel [EMAIL PROTECTED] wrote: Rob, Characters take up one byte... As far as I know... Althoug unicode may take up 4?? I can't remember. I suppose the best estimate would be to multiply the string length by the byte size of each characters: intSizeEstimate = Len( strFileContent ) * 4 -b ... Ben Nadel Web Developer Nylon Technology 350 7th Ave. Suite 1005 New York, NY 10001 212.691.1134 x 14 212.691.3477 fax www.nylontechnology.com Sanders: Lightspeed too slow? Helmet: Yes we'll have to go right to ludacris speed. -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238083 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
RE: Get String Byte Size
Andy, I am not sure how to do this exactly, but maybe something along the lines of: ArrayLen( CreateObject(java, java.lang.String).Init( strFileContent ).GetBytes() ) It creates a string, then gets the byte array (as described in the java docs: Convert this String into bytes according to the platform's default character encoding, storing the result into a new byte array.). Perhaps in this case, the number of bytes would be the size of the memory?? ... Ben Nadel Web Developer Nylon Technology 350 7th Ave. Suite 1005 New York, NY 10001 212.691.1134 x 14 212.691.3477 fax www.nylontechnology.com Sanders: Lightspeed too slow? Helmet: Yes we'll have to go right to ludacris speed. -Original Message- From: Andy Matthews [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 10:03 AM To: CF-Talk Subject: RE: Get String Byte Size I would think that at the Java level there would be some way to get the size of a variable. Maybe these might help?: http://www.roseindia.net/javatutorials/determining_memory_usage_in_java.shtm l http://gcc.gnu.org/ml/java/2003-02/msg00293.html !//-- andy matthews web developer ICGLink, Inc. [EMAIL PROTECTED] 615.370.1530 x737 --//- -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 8:57 AM To: CF-Talk Subject: Re: Get String Byte Size And therein lies the key. I may - or may not - have unicode involved. I was hoping someone knew of some quick java to return the byte size of a string that would handle those vagaries. I haven't found anything in my searches. On 4/19/06, Ben Nadel [EMAIL PROTECTED] wrote: Rob, Characters take up one byte... As far as I know... Althoug unicode may take up 4?? I can't remember. I suppose the best estimate would be to multiply the string length by the byte size of each characters: intSizeEstimate = Len( strFileContent ) * 4 -b ... Ben Nadel Web Developer Nylon Technology 350 7th Ave. Suite 1005 New York, NY 10001 212.691.1134 x 14 212.691.3477 fax www.nylontechnology.com Sanders: Lightspeed too slow? Helmet: Yes we'll have to go right to ludacris speed. -Original Message- From: Rob Wilkerson [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:28 AM To: CF-Talk Subject: Get String Byte Size 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. Thanks. -- Rob Wilkerson ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:238086 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
Re: Get String Byte Size
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