allocation

Any tool to find size of memory allocated dynamically using malloc/realloc?

旧城冷巷雨未停 提交于 2019-12-20 04:43:11
问题 I have a MS-Visual Studio 2005 workspace having all c code. This application(exe) allocates memory dynamically from heap using malloc and realloc. I want to calculate the maximum size allocated size allocated on heap using malloc/realloc by this application program when i run particular test case. I do not want to change the code by noting the malloc sizes and accumulating them, because: a) there can be a scenario, that some memory of 1KB is malloc'ed, then freed, and then a memory of 2KB is

Why should I not separate alloc and init?

老子叫甜甜 提交于 2019-12-20 03:31:33
问题 The normal way to initialise and allocate in Objective-C is NSObject *someObject = [[NSObject alloc] init]; Why is the following not practised? NSObject *someObject = [NSObject alloc]; [someObject init]; 回答1: The main problem is that you might end up using the wrong object. init is special in many classes as it might just release the receiver and instead create a new object that resides at a different address. So your someObject then points to the wrong (uninitialized) instance. There are a

memory allocation for structures elements

允我心安 提交于 2019-12-19 23:29:51
问题 Hi I am having difficulties in understanding about how the memory is allocated to the structure elements. For example if i have the below structure and the size of char is 1 and int is 4 bytes respectively. struct temp { char a; int b; }; I am aware that the size of the structure would be 8. Because there will be a padding of 3 bytes after the char, and the next element should be placed in multiple of 4 so the size will be 8. Now consider the below structure. struct temp { int a; // size is 4

memory allocation for structures elements

风格不统一 提交于 2019-12-19 23:29:07
问题 Hi I am having difficulties in understanding about how the memory is allocated to the structure elements. For example if i have the below structure and the size of char is 1 and int is 4 bytes respectively. struct temp { char a; int b; }; I am aware that the size of the structure would be 8. Because there will be a padding of 3 bytes after the char, and the next element should be placed in multiple of 4 so the size will be 8. Now consider the below structure. struct temp { int a; // size is 4

C++ Size Of Dynamic Memory at Runtime

拈花ヽ惹草 提交于 2019-12-19 18:26:50
问题 This is something I've been wondering for a while and never found an answer for: Why is it that when you allocate something on the heap you cannot determine the size of it from just the pointer, yet you can delete it using just the pointer and somehow C++ knows how many bytes to free? Does this have something to do with the way it is stored on the heap? Is this information there but not exposed by C++? And perhaps this should be a separate question but I think it's pretty related so I'll ask

C++ Size Of Dynamic Memory at Runtime

久未见 提交于 2019-12-19 18:25:21
问题 This is something I've been wondering for a while and never found an answer for: Why is it that when you allocate something on the heap you cannot determine the size of it from just the pointer, yet you can delete it using just the pointer and somehow C++ knows how many bytes to free? Does this have something to do with the way it is stored on the heap? Is this information there but not exposed by C++? And perhaps this should be a separate question but I think it's pretty related so I'll ask

Passing size as argument VS assuming shape in Fortran procedures

有些话、适合烂在心里 提交于 2019-12-19 04:03:09
问题 I'm trying to decide which one of these two options would be the best: subroutine sqtrace( Msize, Matrix, Value ) integer, intent(in) :: Msize real*8, intent(in) :: Matrix(Msize, Msize) real*8, intent(out) :: Value [instructions...] end subroutine sqtrace VS subroutine sqtrace( Matrix, Value ) real*8, intent(in) :: Matrix(:,:) real*8, intent(out) :: Value if ( size(Matrix,1) /= size(Matrix,2) ) then [error case instructions] end if [instructions...] end subroutine sqtrace I understand that

Why Vector's size() and capacity() is different after push_back()

那年仲夏 提交于 2019-12-18 16:49:42
问题 I just starting to learning vectors and little confused about size() and capacity() I know little about both of them. But why in this program both are different? even array(10) is making room for 10 elements and initializing with 0. Before adding array.push_back(5) So array.size(); is 10 that is ok. So array.capacity(); is 10 that is ok. After adding array.push_back(5) So array.size(); is 11 that is ok (already 10 time 0 is added and then push_back add one more element 5 ) . So array.capacity

Why Vector's size() and capacity() is different after push_back()

与世无争的帅哥 提交于 2019-12-18 16:49:08
问题 I just starting to learning vectors and little confused about size() and capacity() I know little about both of them. But why in this program both are different? even array(10) is making room for 10 elements and initializing with 0. Before adding array.push_back(5) So array.size(); is 10 that is ok. So array.capacity(); is 10 that is ok. After adding array.push_back(5) So array.size(); is 11 that is ok (already 10 time 0 is added and then push_back add one more element 5 ) . So array.capacity

Memory pools implementation in C

那年仲夏 提交于 2019-12-18 15:44:26
问题 I am looking for a good memory pool implementation in C. it should include the following: Anti fragmentation. Be super fast :) Ability to "bundle" several allocations from different sizes under some identifier and delete all the allocations with the given identifier. Thread safe 回答1: I think the excellent talloc, developed as part of samba might be what you're looking for. The part I find most interesting is that any pointer returned from talloc is a valid memory context. Their example is: