• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Struct Size

New Here ,
Nov 05, 2007 Nov 05, 2007

Copy link to clipboard

Copied

I am trying to determine the size of a structure, as in byte size, not structCount() before I include it in an error handling email. Does anyone have a solution that does this?

Thanks.
TOPICS
Advanced techniques

Views

3.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 05, 2007 Nov 05, 2007

Copy link to clipboard

Copied

As far as I know, there are no "sizeOf" methods available in Java (or CF as a result), like you would find in languages like C or C++. This is largely due to how much differently Java handles memory allocation than other languages (e.g...heaps, garbage collection, etc)

Unfortunately, the best you could do would be to write a custom routine to recursively crawl through the structure and and count the number of characters present in all of the strings it contains. (assuming this is a structure of purely "simple" data types). You could then provide a rough estimation on bytes allocated to the struct based on the total sum of characters it contains.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 05, 2007 Nov 05, 2007

Copy link to clipboard

Copied

You could WDDX it and then strip the tags out. What would be left
(basically just the xmltext "nodes") would be the actual data. Do a len()
on that, to give you a rough idea of the size.

Although the significant size is not the raw size of the data, but the size
of the string you're emailing. You must be "handling" the struct somehow
to serialise it to include in the email text... how are you doing that?

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 06, 2007 Nov 06, 2007

Copy link to clipboard

Copied

Hi,

Intrestingly, When I tried to obtain the size of a structure through an "coldfusion.runtime.struct" object (by calling the "size()" method) it returned the number of elements rather than returning bytes!.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 06, 2007 Nov 06, 2007

Copy link to clipboard

Copied

> Intrestingly, When I tried to obtain the size of a structure ..

That's what size() is supposed to do. A coldfusion.runtime.struct is a Hashtable. Its size() method is defined here

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Hashtable.html#size()

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 08, 2007 Nov 08, 2007

Copy link to clipboard

Copied

Hi cf_dev2,

Thanks for the explanation and the link, Now I got clarified :-)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 16, 2007 Nov 16, 2007

Copy link to clipboard

Copied

LATEST

This is an interesting problem.

Would something like this get you close enough...

<!--- create the structure object --->
<cfset myStruct = StructNew() />

<!--- add one item with a data-type of simple value --->
<cfset StructInsert(myStruct, "my_key", "my_value") />

<!--- add another with a data-type of array --->
<cfset myArray = ArrayNew(1) />
<cfset ArrayAppend(myArray, "another_value") />
<cfset StructInsert(myStruct, "another_key", myArray) />

<!--- number of bytes as a string --->
<cfset len = ArrayLen(myStruct.toString().getBytes()) />


Good luck!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation