开发者

Is class member function code memory allocated once or at every instantiation of objects?

开发者 https://www.devze.com 2023-02-28 22:01 出处:网络
I\'ve a doubt about this ques开发者_如何学Pythontion, not relatively to a specific language: when I write a class, maybe in C++ or Java, the memory for member function code is allocated once or at eve

I've a doubt about this ques开发者_如何学Pythontion, not relatively to a specific language: when I write a class, maybe in C++ or Java, the memory for member function code is allocated once or at every instance? So, in certain cases, is it better to write them as static?

thanks for replies


Nope, the data portion of the code is loaded separately from the executable section when the OS loads your program into memory. They reside usually into different memory regions (typically, the executable section is a read-only section).

So it basically jumps to the executable portion when a method is called, with a different context on the stack.

You may check this excellent article on linkers: http://www.lurklurk.org/linkers/linkers.html

You will understand how a program is loaded into memory, and executed.

0

精彩评论

暂无评论...
验证码 换一张
取 消