Search Unity

How are BlobAssetReferences disposed?

Discussion in 'Entity Component System' started by tertle, Jul 16, 2019.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Title.

    Trying to partially replicate similar behavior of a BlobAssetReference but I can't find anywhere in source where Release() is called to Free the header.
     
    GilCat likes this.
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    It showed in BlobificationTest.cs for emaple? Or I don't get your question right?
    upload_2019-7-16_21-40-11.png

    Edit: I think I get your question. Release method, it's for manual releasing your BAR if required, but memory clearing it somewhere inside engine I guess, in same place where they allocate 256mb area for blobs, and after scene unloading they just free all 256mb without per Blob Release() call
     
    Last edited: Jul 16, 2019
  3. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    Joachim posted this in a thread where I asked a similar question:
    https://forum.unity.com/threads/rules-and-whys-behind-blobs-and-colliders.690451/#post-4620274

    The TLDR
     
    eizenhorn likes this.
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    -edit- beat me by seconds, thanks for the link i'll go read

    -original-

    Yeah so in Create the header is created with a Persistent allocator

    Code (CSharp):
    1. byte* buffer = (byte*) UnsafeUtility.Malloc(sizeof(BlobAssetHeader) + length, 16, Allocator.Persistent);
    2. UnsafeUtility.MemCpy(buffer + sizeof(BlobAssetHeader), ptr, length);
    3.  
    4. BlobAssetHeader* header = (BlobAssetHeader*) buffer;
    How is this header memory disposed of when you remove a component with a BlobAssetReference?
     
  5. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    What the Header Points to is part of the blob itself.

    You have to think of the structure of a blob like this:
    struct MyBlob
    {
    int Foo;
    BlobPtr<BarData> BarPtr;
    BlobArray<BazData> BazVectors;
    }

    As being this data layout:
    {
    BlobAssetHeader header;
    MyBlob
    {
    Foo;
    BarPtr.Offset
    Baz.Offset
    Baz.Length
    }
    ... padding?
    actual BarData { ... }
    ... padding?
    actual BazVector[N]
    }

    I haven't dived too deep into the actual structure to know if they rearrange stuff / incur padding, and I'm assuming the header is at the beginning (as that's the logical choice barring any performance specific improvements) but that's the basic Gist of it, which is why I had trouble when I passed BlobArray<T> to a function.

    It's not actually a pointer, it's an offset into the blob structure along with the length (in element steps, not bytes) of the array. and when you remove it from that context, it points to other memory upon resolution.

    You either have to get the raw pointer, or they need to add an AsNativeArray() function (which I hope they do).