Structs and the GC

About Monkey 2 Forums Monkey 2 Programming Help Structs and the GC

Tagged: 

This topic contains 17 replies, has 7 voices, and was last updated by  sicilica 2 years, 8 months ago.

Viewing 3 posts - 16 through 18 (of 18 total)
  • Author
    Posts
  • #2688

    Mark Sibly
    Keymaster

    Strings are allocated from the heap, but are reference counted instead of GC’d.

    #2950

    sicilica
    Participant

    In case anyone searches into this thread later with a similar situation, a solution like this should work:

    Vec3_Alloc() can allocate arrays of contiguous memory for storing a large number structs.

    Your struct should only contain pointers if you do this (even, say, a single float needs to be a pointer; classes are fine, since they are always be pointers, but ofc they shouldn’t be allocated from your malloc memory).

    If you allocate an array of structs, they have to all be free’d at once, pass a pointer to the first one to the Vec3_Free() function (duh).

    You still need to store your ACTUAL structs somewhere on the heap, so they are technically separate from the memory, eg:

    And as the last caveat, you’ll fracture your memory a lot worse than even the GC would if you don’t know what you’re doing, so for example, don’t actually create a single triangle this way.

    #2956

    sicilica
    Participant

    Here’s a much better example.

Viewing 3 posts - 16 through 18 (of 18 total)

You must be logged in to reply to this topic.