This content has been marked as final. Show 6 replies
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.
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?
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!.
> 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
Thanks for the explanation and the link, Now I got clarified :-)
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()) />