プログラミング言語 (特に Java) のメモリ モデルに関する知識を深めたいので、1 つ質問があります。
これは非常に単純なコードです:
// Allocating memory in heap for SimpleObject's instance
// Creating reference to this object with name so1
SimpleObject so1 = new SimpleObject();
// Allocating memory in heap for array of 10 references to SimpleObject's objects
// Now I know, that array stores only references to the objects
// (Previously I thought that array stores objects)
// Then we create reference to this array with name soArray
SimpleObject[] soArray = new SimpleObject[10];
今質問:
// What is going on here?
soArray[0] = so1;
// object so1 had been really moved to memory area of soArray?
// And so1 reference have been updated to new memory address?
// Or we just had assigned so1 object's reference to soArray[0] element?
// Or so1 object had been copied to the soArray[0]?
// Then original so1 object has been deleted and all links to it had been updated?
(C、C++、C#など)他の言語でどのように機能するか知っている場合は、答えてください。喜んで教えてくれます。
配列の要素は CPU キャッシュに格納できるため、ArrayList は LinkedList よりも高速になる可能性があることは誰もが知っていますが、LinkedList を使用する場合、CPU は毎回 RAM から次のオブジェクトを取得する必要があります。
では、最初にオブジェクトをヒープに作成してから、オブジェクトを配列に配置した場合、どのように機能するのでしょうか?
UPD: ありがとうございます。これで、配列がどのように機能するかがわかりましたが、そのように配列を CPU キャッシュにキャッシュするのはどうですか?