Need Help: Why Dynamic memory allocation by using pointers provides an efficient way of utilizing computer memory but such memory allocation may be problematic if not handled properly in program.

Member Avatar
Member Avatar
+0 forum 2

These are two simple programs. In first program, i used static array, while in second program i used dynamic array. Both programs do the same job i.e. initiaze the array by asking the user to enter the their test scores. The problem is: 1)i have read in many books that we can't use static array if we do not know the exact size of the array. instead of this we just use dynamic array. but in both these programs we do not know the size of the array. ** according to above statement my first program should not run but …

Member Avatar
Member Avatar
+0 forum 9

`Inline Code Example Here`I am using a pair of pthreads that call a pair of functions for ping-pong dma data transfer that are used in a loop for data transfer from an acquisition board. For a large # of waveforms, I ultimately run out of PC memory and the program stops. At the end of each function I use the delete[] command to clear memory for reuse, but the pointer appears to advance by the array size used for the transfer until the location exceeds the 2 GB I have for memory. I can see this happening using the Task …

Member Avatar
Member Avatar
+0 forum 5

currently I'm rewriting old euler solutions into classes so i can store them in a library. I wrote a program that digitizes a number so it can check to see if it a pallindrome, The base class digitize dynamically allocates memory for the size of a number and stores each digit, My second class pallindrome inherits the members of digitize, and refrences the constructor using the :, however when I construct the pallindrome class i get a back trace error. I know I can probably just not use inheritance and it will work but i want to know why this …

Member Avatar
Member Avatar
+0 forum 2

Hi- I have a script that grabs a lot of information for a page that has a 'Research Mode.' Basically, it grabs a bunch of data, then uses JS to show or hide info based on user criteria. It used to work fine, but we've been adding more info -- & still have more to go -- & I'm running out of memory with the PHP script the generates the page. The error I'm getting is: Fatal error: Out of memory (allocated 23330816) (tried to allocate 5445228 bytes) in (script path) I've tried using: ini_set('memory_limit', '256M'); on the main calling …

Member Avatar
Member Avatar
+0 forum 1

Hi guys, I'm trying to use the random number generator as part of the GSL library and it is working fine for a few hundred 'rounds' of my code (it is used quite a few times per round) but then i get an error message in the command window: [CODE]gsl: rng.c:46: ERROR: failed to allocate space for rng state Default GSL error handler invoked.[/CODE] A quick look at the rng.c shows that this is an error from the gsl_rng_alloc part (see bottom)and this is what I can find about that function on that topic: [CODE]— Function: gsl_rng * gsl_rng_alloc (const …

Member Avatar
Member Avatar
+0 forum 4

Hi, I am new to java and I need to work with arrays. I have found some tutorials, but everywhere was something like [CODE] int[] anArray; // allocates memory for 10 integers anArray = new int[10]; [/CODE] But what if I dont know how long the array will be? When I tried to do just that: [CODE]int[] anArray;[/CODE] Without allocating memory, Im getting error: The local variable anArray may not have been initialized. Can you please help me?

Member Avatar
Member Avatar
+0 forum 3

I'm trying to design Programmable Logical Array using c language. Due to lack of time I downloaded code for tabulation from internet. Now I have modified it to return f and f' in a character array. It works fine for some functions. But it shows memory allocation problem for some inputs. for eg: Number of minterms : 8 Number of don't cares : 6 Don't care terms: 10 11 12 13 14 15 Min terms 0 2 3 4 5 6 7 8 9 Here is my code. I'm using dev-cpp compiler. [CODE] #include<stdio.h> #include<malloc.h> int *f,u; int *d1,d2,d3,var; struct …

Member Avatar
Member Avatar
+0 forum 1

I have a base class and two derived class. One derived class which inherits base class as virtual and another one as non virtual. I have given below my codin. [CODE] // This program uses virtual base classes. #include <iostream> using namespace std; class base { public: int i; }; // derived inherits base as not virtual class derived : public base { public: int x; }; // derived1 inherits base as virtual. class derived1 : virtual public base { public: int j; }; int main() { base b; cout<<endl<<sizeof(b)<<" "; derived obn; cout<<sizeof(obn)<<" "; derived1 ob1; cout<<sizeof(ob1); return 0; …

Member Avatar
Member Avatar
+0 forum 1

Hello everybody, I have never done anything with dynamic memory allocation and was trying to allocate enough memory to hold four elements of an array. Each of these elements will hold another array that will hold the actual data. My questions is how can I check the size of a variable to make sure there is enough memory allocated. I am not talking about using an if statement. I would like the actual value of how much memory the variable uses. [CODE] //Declaration of variable int *matrices = NULL; //Pointer to the set of matrix registers matrices = (int*) malloc(4 …

Member Avatar
Member Avatar
+0 forum 3

I'm not known to be a very memory friendly guy but after about 4 hours debugging my lua+sdl in C++ I finally figured out how to use threads but now I have another problem. I apparently have zero knowledge of memory manangement but thats kind of ok so I've narrowed the error down to the function void lsmain() lsmain.h [CODE] #ifndef _LSMAIN_H_ #define _LSMAIN_H_ #include <lua.hpp> #include <iostream> #include <SDL/SDL.h> #include <SDL/SDL_thread.h> using namespace std; bool quit = false; void interpret(lua_State* L){ int error; int x = 0; char buffer[256]; while(x == 0){ cout<<"Lua >> "; cin.getline(buffer,256); error = luaL_loadbuffer(L,buffer,strlen(buffer), …

Member Avatar
Member Avatar
+0 forum 5

Hello guys, I am trying to declare a two dimensional array in C++ on runtime. For this purpose I am asking the user about how many rows and columns should be created in the array. I have written the following code for this purpose. Apparently it is working just fine. But I am asking you if you can identify any mistake or error in this code especially in the memory deallocation part. Am I correctly releasing all the memory that I first allocated at the beginning of the program. Actually my course instructor touched this topic very slightly and also …

Member Avatar
Member Avatar
+0 forum 7

Hi all. I have detected something that I can't explain, and hope someone can help me. I have 2 functions for allocating and de-allocating arrays: [CODE]char **c; void allocate() { char **c = new char*[1000]; for(int i = 0; i < 1000; i++) { char *g = new char[10000]; for(int j = 0; j < 10000; j++) { g[j] = 'k'; } c[i] = g; } } void deallocate() { for(int i = 0; i < 1000; i++) { delete [] c[i]; c[i] = NULL; } delete c; c = NULL; } void test() { cout<<"Start Memory: "<<getMemory()<<endl; cout<<"Start Time: …

Member Avatar
Member Avatar
+0 forum 5

The End.