memory-management

How is an array of objects stored in memory?

喜夏-厌秋 提交于 2019-12-24 14:51:24
问题 I know a contiguous block of memory is allocated for an array. My first question is when the array element is an object rather than a built-in type, what gets stored in the contiguous memory reserved for the array? Pointer for the object or the actual data for the object? My guess is pointers are stored in the array and the actual objects are stored randomly in the heap. Am I correct? My second question is now we want to reserve a specified memory(e.g., shared memory) for an array of objects.

Passing a triple pointer to allocate memory in another function, sscanf exception

笑着哭i 提交于 2019-12-24 14:47:22
问题 Im allocating memory to a double pointer in another function, therefore I need to use a pointer to the pointer to the pointer. Im getting an exception thrown when i use sscanf, im not sure exactly why. Heres a snippet of the code. This was working earlier when it was all in the same function and i only needed to use double pointers, but now that im refactoring the code and using triple pointers im having this issue. typedef float vector[3] int mainLoaderFunc() { char* memory = NULL; size_t

Is it nessary to destroy a string before constructing it again?

北战南征 提交于 2019-12-24 14:21:10
问题 As an exercise, I'm trying to write a class like a std::vector without using a template. The only type it holds is std::string . Below is the strvec.h file: class StrVec { public: //! Big 3 StrVec(): element(nullptr), first_free(nullptr), cap(nullptr) {} StrVec(const StrVec& s); StrVec& operator =(const StrVec& rhs); ~StrVec(); //! public members void push_back(const std::string &s); std::size_t size() const { return first_free - element; } std::size_t capacity() const { return cap - element;

What is wrong with this command?

我怕爱的太早我们不能终老 提交于 2019-12-24 14:01:50
问题 I'm not a software/scripting folk myself so struggling to understand what is happening here: watch -n 0.2 'ps -p $(pgrep -d',' -x snmpd) -o rss= | awk '{ i += $1 } END { print i }'' Basically I am wanting to print the Resident Set Size value of my snmp daemon 5 times a second (for fair resolution). I then intend on building from this to redirect the output to a text file for later analysis where I can put the data into a graph for instance. The trouble I have here is that I can run the

Advantage/Disadvantage of function pointers

余生长醉 提交于 2019-12-24 13:26:10
问题 So the problem I am having has not actually happened yet. I am planning out some code for a game I am currently working on and I know that I am going to be needing to conserve memory usage as much as possible from step one. My question is, if I have for example, 500k objects that will need to constantly be constructed and deconstructed. Would is save me any memory to have the functions those classes are going to use as function pointers. e.g. without function pointers class MyClass { public:

Android and running OOM with free heap space left

孤人 提交于 2019-12-24 13:24:40
问题 I have an app running OOM with plenty of free heap space free and available to grow on a stock Galaxy S3. The app runs fine on other devices. Knowing that in traditional Java this can be caused by being OOM within the permanent generation space, I tried looking into how Dalvik handles this, but couldn't find anything definitive. Androids SDK seems to be missing both MemoryUsage and ManagementFactory, so I can't get them as you would in Java. I'm trying to find out if Android has a permanent

Xcode static analyser complaining about potential leak when using ARC

こ雲淡風輕ζ 提交于 2019-12-24 12:34:21
问题 I am using ARC with ios sdk 6.0. I am pretty sure I have got some memory leaks which Im having trouble tracking down. After running the static analyser, im getting warnings about the following two methods: + (id<MXURLRequest>) requestWithURL:(NSURL*)url { MXASIURLRequest *request = [[MXASIURLRequest alloc] init]; [request setUrl:url]; return request; // STATIC ANALYSER: Potential leak of an object stored into 'request' } - (id)parseBody:(NSError *)error { NSString *contentType = [[_request

Pragma Pack used C library causing the jvm to crash

我是研究僧i 提交于 2019-12-24 12:27:50
问题 I used a C library in my Java code using JNA. I have these C structures of whose members I need to print in Java. Because of the memory alignment and padding the size was differing from what I was actually expecting. Therefore I used pragma pack and this is how the structures look like now. #define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) ) PACK( typedef struct { size_t size; uint8_t bytes[48]; } ipj_tid_t); PACK( typedef struct { bool has_epc; //1

strsep segmentation faults on different string pointer/array types

ε祈祈猫儿з 提交于 2019-12-24 12:15:00
问题 Platform: Linux, OSX Compiler: GCC I've got a simple program which is currently confounding me - I know that I'm messing with a couple different kinds of arrays/pointers to produce this problem - its intentional - I'm trying to understand it. The code as listed will compile and run as expected, but changing data4 in the call to strsep(&data4, "e"); to data1 or data3 causes a segmentation fault. I would like to understand why. #include <stdio.h> #include <string.h> int main(int c, char** v) {

Analyzing kmemleak result

北战南征 提交于 2019-12-24 12:09:26
问题 I am running kmemleak on one of my modules to find leaks, below is the result after a while. From the result, what i understand is below address are object/s address in the .ko or .o file. unreferenced object 0xffff8803c9708f10 (size 32): comm "resiter_access_i_o", pid 2320, jiffies 4294798486 hex dump (first 32 bytes): d8 8e 70 c9 03 88 ff ff a0 8e 70 c9 03 88 ff ff ..p.......p..... 68 8e 70 c9 03 88 ff ff 30 8e 70 c9 03 88 ff ff h.p.....0.p..... backtrace: [<ffffffff81516e3e>] kmemleak