Pointer Size - How big is an object reference?

后端 未结 2 764
情歌与酒
情歌与酒 2020-12-15 05:07

The question finishes after the first horizontal line, the rest is extra information.

The question is simple, what is the size that a ref

2条回答
  •  萌比男神i
    2020-12-15 06:04

    References are nearly free. Even more so when compared to images.

    Having a few collisions in a Map isn't a real problem. Collisions can be resolved far quicker than a linear search through a list of items. That said, a Binary Search through a sorted list of items would be a good way to keep memory usage down (compared to a Map).

    I can vouch for the effectiveness of a having smaller initial sizes for Maps - I recently wrote a program that makes a Trie structure of 170000 English words. When I set the initial size to 26, I would run out of memory by the time I got to words starting with R. Cutting it down to 5, I was able to create the maps without memory issues and can search the tree (with many collisions) in effectively no time.

    [Edit] If a reference is 32 bit (4 bytes) and your average image is around 2 megabytes, you could fit 500000 references into the same space that a single image would take. You don't have to worry about the references.

提交回复
热议问题