Search Unity

Objects Memory Allocation

Discussion in 'Scripting' started by iamfeyre, Feb 14, 2018.

  1. iamfeyre

    iamfeyre

    Joined:
    May 20, 2016
    Posts:
    56
    Ok so i was wondering how much memory is allocated when i make an array of say colliders. Like int is 4 bytes.. collider is of how much memory?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    The short answer is, it's undefined and you shouldn't worry about it.

    The longer answer is: the array itself is probably 4 (but maybe 8, depending on platform and build settings) bytes per entry, plus a small but undefined bit of overhead, as colliders are objects, and an array holds only the object references; so what would really matter is how many of those array entries point to unique objects; and then the actual size of such an object certainly depends on which collider subclass it happens to be, plus whatever under-the-hood (and thus undefined) data structures Unity has associated with it; but whatever it is, it is certain to be absolutely trivial compared to, say, one good-sized texture or sound effect; so you shouldn't worry about it.
     
    lordofduct and iamfeyre like this.
  3. iamfeyre

    iamfeyre

    Joined:
    May 20, 2016
    Posts:
    56
    thanks
    i was just worried that I couldn't set a value for my collider array to a high value..
     
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    A hashset containing terrain meshes (not unity terrain) in a 50,000 unit radius uses up about 4mb in my application, it can be reduces quite a bit..