Golang app default memory restrictions?

I have a machine with tons of memory. I have a golang µService that uses some memory. I have an option to choose from A) store that memory in a an array (contigous memory), or B) in a tree.

Does the face that the tree does not need contiguous memory, influence my decision ? The machine should have enough memory to store what I need in an array, this is not a factor. Is there perhaps a default max memory limit set by Golang ?

Hi @heidi ,

An array stores it’s size in an int. (See Array types.) It’s maximum number of entries is therefore 9,223,372,036,854,775,807 (on a 64-bit architecture), which should be more than your RAM can hold.

How you store data is largely determined by how you need to access it. Arrays are good for linear reading, but for quick random access, a balanced search tree would be preferable.

I declare a large array, that happens to be larger than my RAM, what would happen ? It should not crash, but only parts of it would be loaded in RAM at the same time.

I too think that for large data which can be stored both in an slice or a tree, the slice will have another advantage, its cache locality will matter less, as 2 logically close items will not be close in memory (the children of a tree node are not close in the large slice).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.