array in struct bug?

About Monkey 2 Forums Monkey 2 Development array in struct bug?

This topic contains 5 replies, has 3 voices, and was last updated by  Mark Sibly 2 years, 3 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6087

    abakobo
    Participant

    this code shows an array modified in the orriginal struct though the struct was/should_be passed by value to the function..

    [/crayon]
    #6088

    codifies
    Participant

    Field arr:=New Int[20]

    isn’t that in effect a pointer, so the pointer isn’t modified but rather what it points to (which isn’t actually in the struct) ie **New** Int[]

    #6090

    abakobo
    Participant

    Yes and no ;P, but i thought that it would create a full copy so the pass by value would be consistent..

    #6094

    codifies
    Participant

    The problem is that the array isn’t actually physically in the struct and good job because it would be copying the whole array each time you passed it anywhere…

    I definitely think structs are useful for just small collections primitives for example four values defining a rectangle, trying to use it as light weight class is going to be more trouble than its worth…

    #6095

    abakobo
    Participant

    Indeed

    #6122

    Mark Sibly
    Keymaster

    Arrays types are, like objects, reference types so are never ‘value copied’.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.