|
|
where the vtable memory will be sotred? |
|
Author |
Message |
yln

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
hello ,
where the vtable memory will be created . Virtual functions callings are resolved at runtime . but when i write the class which has a virtual functions iam getting the size of the class = data + vptr but where the vtable memory is stored
Visual C++13
|
|
|
|
 |
Jonathan Caves - MSFT

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
The virtual function table is in memory - there is one slot for each virtual function + if you are using RTTI (Run Time Type Information) there is a slot for the RTTI data. Where exactly in memory isn't really important unless you are writing device drivers that will run in kernel mode - in which case why are you using virtual functions
|
|
|
|
 |
yln

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
ya,
everyone knows it should be in the memory. My doubt is in which area it will be allocated i.e how to address it . are they stored in my process address or any other
address space .
One more is
if suppose my dll contains classes , what about these classes vtables . where the vtables of those classes are allocated
please answer me
|
|
|
|
 |
Jonathan Caves - MSFT

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
All the virtual function tables are in the memory associated with your process. With Visual C++ 2005 all virtual function tables are stored in read-only memory - this is protect the virtual function table from being modified.
|
|
|
|
 |
yln

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
hello ,
so if any dll contains classes the corresponding vtables memory is allocated in the corresponding address space i.e corresopingig processes virtual address space . so there are multiple vtables per class which are in the dll (= the number of processes addressing the dll ). right
|
|
|
|
 |
Jonathan Caves - MSFT

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
I'm sorry but I don't completely understand your question: a DLL is never shared across processes - each process has its own copy of the DLL.
|
|
|
|
 |
yln

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
what each processes has its own copy of the dll . Then what is the use of dll .
What ever i have studied so far ( from Programming application for microsoft windows by Jeffrey richter ,programming windows charles petzold ,programming windows with mfc by jeff prosise) is there is only one copy of dll is exist and per each processes global and static varibles which are in the dll are stored separately .
is it wrong or did i study some wrong books
if your assumption is right then each process which are using mfc has its own copy of the mfc42 dll .
|
|
|
|
 |
cythe

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
When you make any function virtual, the compiler will insert a vptr inside your class. As a result, the size of the class will grow by 4 bytes (on Win32).This pointer holds the address of the virtual table (vtable). vtable is constructed by the compiler at compile time and is basically nothing but an array of function pointers. The function pointers are actually pointers to the virtual functions of that particular class. To be more exact, the virtual table is a static array of function pointers, so that different instances of the same class can share that vtable. Since, static members are stored in the data section (.data), the vtable is also stored in the data section of the executable.
The vptr is initialized to the vtable in the constructor.
Regarding Dlls, actually the dlls are mapped inside the address space of the process which is using them. The OS will create pages in the RAM for the Dll. Those pages will be shared between the processes only if they are read only (typically the executable code). If the page has read/write access, then the data will be in multiple pages so that each process can have its own version of that data.
|
|
|
|
 |
yln

|
Posted: Visual C++ Language, where the vtable memory will be sotred? |
Top |
thank u ,
I got the answer .excellent answer
|
|
|
|
 |
|
|