PDA

View Full Version : Little question about struct and functions


arketip
03-12-2006, 11:55 AM
When I write a function included in a structure, is the function unique in memory or a copy of this function is realized for each element defined by this structure?

struct person (
name, height, weight,
fn bmi = ( weight/(height^2) )
)

bill = person name:"Bill" height:1.82 weight:72
joe = person name:"Joseph" height:1.68 weight:78

bill.bmi()
joe.bmi()
For example here the function bmi () is twice copied in memory : once for bill and once for joe ?

Thanks

PEN
03-12-2006, 01:56 PM
Yes I believe this is the case. You are making an instance of the whole struct.

arketip
03-13-2006, 08:05 AM
Paul, thank you very much for your reply.
That is an important point when i use big arrays of struct...

PEN
03-13-2006, 11:25 AM
I guess that I look at Structs as having two seperate jobs, one for managing data and the other for managing code and I don't tend to mix them. If you want to drop your function in a struct then have a second struct that you call to do all the work. That way you only need one instance of it running.

stuh505
03-13-2006, 12:49 PM
I don't think this is correct, see my previous thread--

http://forums.cgsociety.org/showthread.php?t=285432&highlight=function

PEN
03-13-2006, 01:53 PM
Ah well that is good news. I thought that it was the other way. Thanks for stepping in.

arketip
03-13-2006, 07:02 PM
stuh, do you remember what kind of speed test you used ?
I would have thought of a memory test... but that does not seem possible in maxscript.

stuh505
03-13-2006, 08:16 PM
changed your name, prettypixel?

stuh, do you remember what kind of speed test you used ?

I did a speed test, because allocating memory is bound to take time.

To make a controlled experiment I create both a small and large struct, then make X instances of one of those, and take the total time. It should not take more time to make 100,000 instances of one or the other.

If you run the test sometimes one is faster or the other, or sometimes they are equal....this is due to GC interference

<<script attached>>

I would have thought of a memory test... but that does not seem possible in maxscript.

Actually, it is:


#()

5417244

58136250

(smallStruct a:1)

(bigStruct )

-- Error occurred in i loop; filename: D:\Documents and Settings\Owner\Desktop\speedTest.ms; position: 35079

-- Frame:

-- i: 171628

-- Runtime error: Out of scripter memory - use options to increase

58137031

#()

5800632

58137187

(smallStruct a:1)

(bigStruct )

-- Error occurred in i loop; filename: D:\Documents and Settings\Owner\Desktop\speedTest.ms; position: 35308

-- Frame:

-- i: 180945

-- Runtime error: Out of scripter memory - use options to increase

58137921



Here you can see the scripter ran out of memory at 171628 small structs, and also at 180945 large structs....so the large ones definitely arent taking up more memory :P

arketip
03-13-2006, 09:31 PM
It is a crash test :p

well as usual you are right.
We can even create more copies of the biggest structure :/
That is the precision of the computers... The worst is to understand that there is probably a logical reason in it.

nice tree ^^

Thank you mister Stuh

stuh505
04-08-2006, 06:03 AM
sysinfo.getSystemMemoryInfo()

Returns a 7 element array containing system memory status data. The array elements contain the following, respectively:

<LI style="FONT-SIZE: 10pt">percent of memory in use

<LI style="FONT-SIZE: 10pt">bytes of physical memory

<LI style="FONT-SIZE: 10pt">free physical memory bytes

<LI style="FONT-SIZE: 10pt">bytes of paging file

<LI style="FONT-SIZE: 10pt">free bytes of paging file

<LI style="FONT-SIZE: 10pt">user bytes of address space

free user bytes

CGTalk Moderation
04-08-2006, 06:03 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.