memory-management

Best way to find memory leaks in a C program

流过昼夜 提交于 2019-12-23 12:54:39
问题 I am trying to complete a college assignment, and the marking criteria specifies 5% for memory management - specifically for having no memory leaks. As I understand it, memory leaks in simple C programs, are only caused by pointers which have become abandoned by the program - ie, malloc/calloc/etc calls which are never have a corresponding free . My question is in 3 parts: Whats the simplest way on Solaris and OSX to 'prove' that you haven't leaked any memory? Does XCode have any tools to

Autorelease: Use always when you've NARC'ed?

蓝咒 提交于 2019-12-23 12:46:49
问题 I know this question looks like a dupe: I checked and it's not In talking about NARC, the author of this blog says, "Personally, I like to immediately autorelease anything I NARC-ed, on the same line." This goes completely counter to all the examples I've seen on the Apple site and in books, where autorelease is only used when the object must be returned and cannot be released immediately. In general, the idea is that autorelease is memory intensive and can gum up your program (though it

How does Go allocate memory in make or new calls?

自闭症网瘾萝莉.ら 提交于 2019-12-23 12:27:15
问题 When I create a new slice or struct with a make or new call: s := make([]int64, 10, 100) o := new(MyStruct) How much memory does Go allocate with a memory allocation system call? Does it pre-allocate memory, so that subsequent calls don't trigger new system calls? I am asking this because I need to allocate memory frequently in my code. I am not sure if I need to implement a memory allocater myself, or if I can depend on Go to do the dirty work. And if Go does pre-allocate memory, can I

Proguard rules for Android support library (v4 & v7)

佐手、 提交于 2019-12-23 12:13:44
问题 I use, android support library v4 and v7 in my app. I am using only few widgets from the support library (not all of them). But in final release API, 18K functions are included from support libraries. (screenshot attached) How to reduce them? Following is my proguard config. -optimizationpasses 3 -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content

Memory allocation stack

本秂侑毒 提交于 2019-12-23 12:13:26
问题 In the stack, memory is reserved for main which we call stack frame for the main function. When we call the Add function, memory is reserved on top of the stack. In the Add function stack frame, a and b are local pointers and c is an integer which calculates the sum and then we return the reference. c is a local variable of Add function. Now when the Add function execution is completed the memory space in the stack is also deallocated so when we try to access this address in the main with

Efficient handling of super wide, but not so tall, bitmap?

风格不统一 提交于 2019-12-23 11:55:55
问题 Is there any way to create a more space/resource efficient bitmap? Currently I try to render a file, approx 800px high but around 720000px wide. It crashes my application, presumably because of the share memory-size of the bitmap. Can I do this more efficiently, like creating it as an gif directly and not later when I save it? I try to save a series of lines/rectangles from a real world reading, and I want it to be 1px per 1/100th of a second. 回答1: You have to remember that any image you load

Which memory area is a const object in in C++? [closed]

梦想的初衷 提交于 2019-12-23 11:09:08
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I'm not asking what stack/heap/static mean or what is the different between them. I'm asking which area a const object in? C++ code:

Where is the memory allocated when I create this array? (C)

徘徊边缘 提交于 2019-12-23 10:57:41
问题 Let's say I do something like: char* test[] = {"foo","bar","car"}; What exactly is this equivalent to if I did it the long way? Is this automatically creating memory that I will need to free? I'm just sort of confused. Thanks. 回答1: test is an array of pointers to char located on the stack, and the string literals "foo" , "bar" , "car" are stored in a read only location. You need to free nothing. test[0] , test[1] , test[2] point to read-only data. Please read about scoping rules and variable

Is memory address 0x0 usable?

霸气de小男生 提交于 2019-12-23 10:30:09
问题 I was wondering... what if when you do a new, the address where the reservation starts is 0x0? I guess it is not possible, but why? is the new operator prepared for that? is that part of the first byte not usable? it is always reserved when the OS starts? Thanks! 回答1: The null pointer is not necessarily address 0x0 , so potentially an architecture could choose another address to represent the null pointer and you could get 0x0 from new as a valid address. (I don't think anyone does that, btw,

video gets stuck when its seeked back (C++) (QT) (libvlc)

梦想的初衷 提交于 2019-12-23 10:19:13
问题 I am using libvlc to play video on my GUI Application using QT 4. When I seek forward the video it works fine, but when I seek back the video, it gets stuck I mean frame doesn't change and my callback function which is videopostrender doesn't get any call. void videoPrerender(void *p_video_data, uint8_t **pp_pixel_buffer, int size) { // Locking //printf("cbVideoPrerender %i\n",size); //printf("vtest: %lld\n",(long long int)p_video_data); VLCPlayer* player = reinterpret_cast<VLCPlayer*>(p