memory-layout

Address of a Global Variable in the Heap Address Range

旧巷老猫 提交于 2019-12-06 10:49:23
I was debugging the MPlayer-1.3.0 source code, and I saw a global variable whose address (returned by GDB or even simple printing) was in the range for the heap allocations, instead of the data section. I checked the heap range using procfs . 555555554000-555555834000 r-xp 00000000 08:12 798876 /usr/bin/mplayer 555555a33000-555555b25000 r--p 002df000 08:12 798876 /usr/bin/mplayer 555555b25000-555555b2b000 rw-p 003d1000 08:12 798876 /usr/bin/mplayer 555555b2b000-555556479000 rw-p 00000000 00:00 0 [heap] 7fffc3fff000-7fffc8000000 rw-s 00000000 00:16 1932 /dev/shm/pulse-shm-3887887751 The

memory profiling for C program

纵然是瞬间 提交于 2019-12-06 01:39:39
问题 Need to do a memory profiling of my C application .. It should include footprint size and a RAM size ... for example if my application is like below .. #include <stdio.h> int global = 10; /* initialized global variable */ int test_code(void) { static int i = 100; /* Initialized static variable*/ return 0; } Output: [putta@linux]$ gcc memory-layout.c -c memory-layout [putta@linux]$ ls -ltrh memory-layout.o 760 Nov 9 18:26 memory-layout [putta@linux]$ size memory-layout.o text data bss dec hex

Does linux provide a guaranteed inaccessible memory area below the lower stack end?

混江龙づ霸主 提交于 2019-12-05 23:20:45
Does Linux provide an inaccessible memory area below the lower stack end that has a guaranteed minimum size? And if such a guaranteed minimum size exists, what is it? Or in other words, when should I start to worry about alloca() or so giving me pointers into valid, non-stack memory? As the alloca man page says: There is no error indication if the stack frame cannot be extended. (However, after a failed allocation, the program is likely to receive a SIGSEGV signal if it attempts to access the unallocated space.) So there is no indication at all and it also says: If the allocation causes stack

Using reflection to determine how a .Net type is layed out in memory

白昼怎懂夜的黑 提交于 2019-12-05 17:31:15
问题 I'm experimenting with optimizing parser combinators in C#. One possible optimization, when the serialized format matches the in-memory format, is to just do an (unsafe) memcpy of the data to be parsed over an instance or even many instances of the type. I want to write code that determines if the in-memory format matches the serialized format, in order to dynamically determine if the optimization can be applied. (Obviously this is an unsafe optimization and might not work for a whole bunch

Why is vptr stored as the first entry in the memory of a class with virtual functions?

北城余情 提交于 2019-12-05 14:28:05
For some compilers, if a class has virtual functions then its vptr can be accessed with the address of the first byte of its object. For instance, class Base{ public: virtual void f(){cout<<"f()"<<endl;}; virtual void g(){cout<<"g()"<<endl;}; virtual void h(){cout<<"h()"<<endl;}; }; int main() { Base b; cout<<"Address of vtbl:"<<(int *)(&b)<<endl; return 0; } I know that it is dependent on different compiler behaviors. Since there is the case where vptr is stored as the very first entry, what is the advantage of doing this? Does that help improve performance or simply because it's easier to

Virtual inheritance and empty vtable in base class

雨燕双飞 提交于 2019-12-03 20:29:58
There is this code: #include <iostream> class Base { int x; }; class Derived : virtual public Base { int y; }; int main() { std::cout << sizeof(Derived) << std::endl; // prints 12 return 0; } I have read that when some class is virtually inherited then there is created empty vtable for class Derived, so memory layout is as follows: Derived::ptr to empty vtable Derived::y Base::x and it is 12 bytes. The question is - what is purpose of this empty vtable if there are not any virtual methods and how is it used? Derived needs some way to know where the Base subobject is. With virtual inheritance,

How does a memory map of a Windows process look like?

别来无恙 提交于 2019-12-03 06:50:41
问题 This might be a duplicate question. I wish to know how the memory map of a windows process look like? I am looking for details. Kindly provide links to blogs, articles and other relevant literature. 回答1: I always like to actually be able to see things, rather than just read theory. It turns out, according to this blog post, that if you open a program using windbg even when it isn't running it still gets mapped to an address space as if it were. Thus, your disassembly window figuratively (not

How does a memory map of a Windows process look like?

你说的曾经没有我的故事 提交于 2019-12-02 19:24:50
This might be a duplicate question. I wish to know how the memory map of a windows process look like? I am looking for details. Kindly provide links to blogs, articles and other relevant literature. I always like to actually be able to see things, rather than just read theory. It turns out, according to this blog post , that if you open a program using windbg even when it isn't running it still gets mapped to an address space as if it were. Thus, your disassembly window figuratively (not guaranteed to load your code at these exact addresses) shows you what is at those addresses in terms of

Array of non-contiguous objects

杀马特。学长 韩版系。学妹 提交于 2019-12-02 08:59:54
问题 #include <iostream> #include <cstring> // This struct is not guaranteed to occupy contiguous storage // in the sense of the C++ Object model (§1.8.5): struct separated { int i; separated(int a, int b){i=a; i2=b;} ~separated(){i=i2=-1;} // nontrivial destructor --> not trivially copyable private: int i2; // different access control --> not standard layout }; int main() { static_assert(not std::is_standard_layout<separated>::value,"sl"); static_assert(not std::is_trivial<separated>::value,"tr")

Array of non-contiguous objects

喜你入骨 提交于 2019-12-02 07:34:58
#include <iostream> #include <cstring> // This struct is not guaranteed to occupy contiguous storage // in the sense of the C++ Object model (§1.8.5): struct separated { int i; separated(int a, int b){i=a; i2=b;} ~separated(){i=i2=-1;} // nontrivial destructor --> not trivially copyable private: int i2; // different access control --> not standard layout }; int main() { static_assert(not std::is_standard_layout<separated>::value,"sl"); static_assert(not std::is_trivial<separated>::value,"tr"); separated a[2]={{1,2},{3,4}}; std::memset(&a[0],0,sizeof(a[0])); std::cout<<a[1].i; // No guarantee