memory-management

What is considered a small object in C++?

寵の児 提交于 2020-01-02 04:11:10
问题 I've read about Small-Object Allocation in "Modern C++ Design". Andrei Alexandrescu argues that the general purpose operators (new and delete) perform badly for allocating small objects. In my program there are lot of objects created and destroyed on the free store. These objects measure more than 8000 bytes. What size is considered small? Are 8000 bytes small or big when it comes to memory allocation in C++? 回答1: The definition of "small" varies, but generally speaking, an object can be

Is it safe to free() memory allocated by new? [duplicate]

天涯浪子 提交于 2020-01-02 03:45:49
问题 This question already has answers here : new, delete ,malloc & free (2 answers) Closed 5 years ago . I'm working on a C++ library, one of whose functions returns a (freshly allocated) pointer to an array of doubles. The API states that it is the responsibility of the caller to deallocate the memory. However, that C++ library used to be implemented in C and the function in question allocates the memory with malloc() . It also assumes that the caller will deallocate that memory with free() .

Java: getter method vs. public instance variable: performance and memory

橙三吉。 提交于 2020-01-02 03:32:06
问题 Sorry for the noob questions. Passing by reference vs. value is hard! So I have a class with pretty big data structures-- multidimensional arrays. I need to access these arrays from another class. I could just make the arrays public and do the classic objectWithStructures.structureOne. Or, I could do getters: adding a method like public int[][][] getStructureOne(). Does having a getter make a copy of the multidimensional array? Or does it pass it by reference and you just can't alter the

In vb.net, if I use AddHandler, Do I have to use RemoveHandler?

倖福魔咒の 提交于 2020-01-02 02:47:06
问题 If I always need to call RemoveHandler after using AddHandler, where is the best place to do so? I have searched several similar questions as follows, but I do not quite understand. When and where to call the RemoveHandler in VB.NET? AddHandler/RemoveHandler Not Disposing Correctly I thought garbage collection in c# or vb.net will take care of unused objects. Also, in vb.net designer, it automatically generates Dispose Sub. So I did not pay attention to programally releasing resource at all.

Does realloc of memory allocated by C11 aligned_alloc keep the alignment?

不羁的心 提交于 2020-01-02 01:31:05
问题 Consider the following (C11) code: void *ptr = aligned_alloc(4096, 4096); ... // do something with 'ptr' ptr = realloc(ptr, 6000); Since the memory that ptr points to has a 4096-byte alignment from aligned_alloc , will it (read: is it guaranteed to) keep that alignment after a (successful) call to realloc ? Or could the memory revert to the default alignment? 回答1: The alignment is not kept with the pointer. When you call realloc you can only rely on the alignment that realloc guarantees. You

How to get make stats in constant memory

孤者浪人 提交于 2020-01-01 18:19:54
问题 I have a function, which creates some random numerical results. I know, that the result will be an integer in a (small, a - b approx 50) range a, b . I want to create a function which execute the above function let's say 1000000 times and calculates, how often the each result appears. (The function takes a random generator to produce the result.) The problem is, I don't know how to do this in constant memory without hard-coding the range's length. My (bad) approach is like this: values ::

Program heap size?

半腔热情 提交于 2020-01-01 17:57:49
问题 Is the maximum heap size of a program in C fixed or if I keep malloc-ing it will at some point start to overflow? Code: while(connectionOK) //connectionOK is the connection with server which might be forever { if(userlookup_IDNotFound(userID)) user_struct* newuser = malloc(getsize(user_struct)); setupUserAccount(newuser); } I am using gcc in ubuntu/ linux if that matters. I know something like getrlimit but not sure if it gives heap size. Although it does give the default stack size for one

Program heap size?

最后都变了- 提交于 2020-01-01 17:57:45
问题 Is the maximum heap size of a program in C fixed or if I keep malloc-ing it will at some point start to overflow? Code: while(connectionOK) //connectionOK is the connection with server which might be forever { if(userlookup_IDNotFound(userID)) user_struct* newuser = malloc(getsize(user_struct)); setupUserAccount(newuser); } I am using gcc in ubuntu/ linux if that matters. I know something like getrlimit but not sure if it gives heap size. Although it does give the default stack size for one

“Live” memory analysis tool for Android

大兔子大兔子 提交于 2020-01-01 16:59:27
问题 Is there a "live" memory profiler tool (similar to Instruments in XCode) for Android? Most searches for memory profiling, leads me to Memory Analyzer Tool (which is great), but I would very much appreciate a tool which can dynamically show me which classes consume (and release) memory during the life-cycle of my application, as it is executing. Note: I am not looking for a memory profiling tool for Android (Memory Analyzer Tools works very well for me). All the methods/tools I have

“Live” memory analysis tool for Android

旧街凉风 提交于 2020-01-01 16:59:06
问题 Is there a "live" memory profiler tool (similar to Instruments in XCode) for Android? Most searches for memory profiling, leads me to Memory Analyzer Tool (which is great), but I would very much appreciate a tool which can dynamically show me which classes consume (and release) memory during the life-cycle of my application, as it is executing. Note: I am not looking for a memory profiling tool for Android (Memory Analyzer Tools works very well for me). All the methods/tools I have