I have a question about allocating 2MB memory then filling it...
@ Platform:
=> DOS, and application is compiled/linked via Watcom C + DOS32/A (...memory model is "flat" mode)
@ phenomenon:
1. I allocate 2M memory by calloc() function. Then I got "!NULL" and it means allocating 2MB memory is ok( right ? )
2. then I tried to "fill" this 2MB memory by for loop(one byte by one byte) like below:
for( DWORD i=0; i<0x200000; i++) {
*((BYTE *)(A[0].B[0]->C) + i ) = 0x5A; // C is 4-byte address value
}
here :
* DWORD means "unsigned long(4-byte)" and 0x200000 means "2MByte"
* in actual case the value of pointer(to allocated memory) is 3019AF3C(~768MB) <- running in flat mode...
3. after filling this range of memory(2MB) the application crashed...
@ my observations:
1. if allocating 2MB and no fill(no write data to memory) => OK
2. if allocating 2MB and just fill the former 32 bytes => OK
3. if allocating 4KB and fill all => OK
my question is: why can't I filling this 2M memory totally "even memory allocation succeeds" ?
I'm using C++ Form Application in Visual Studio 2010. I defined a new two dimentional array. like this "static int dizi[26][26];" I want to change the value when I clicked the button1. For example, I can change as dizi[2][3]=1. But I couldn't change like in this code. dizi[a][b]=1 didn't happen.
Error is... "access violation exception was unhandled. attempted to read or write protected memory. this is often an indication that other memory is corrupt."
I don't use zeroth variable here.So, It started from 1. My problem is variable can't be changed.I can't assign a value to variable. I have to use 'ogrenci[i].ders[j]'s index for dizi array in this code. It's really weird.
I have a question concerning shared memory (in linux-environment). In our company we currently have an application that is restarted once in a while. There are multiple instances running of this application (on different physical machines), and all access the same centralized database. Because of IO and Network bottleneck the start gets very slow, and takes about 10 Minutes. Besides some new data, most of the data stays the same, so reading from the database again is quite redundant. An idea is to write all relevant object to a shared memory segment, when the application is shut down. A second dummy process attaches to the same shared memory (just so that some process is still attached). If the application is restarted, it is attached again to its shared memory, and reads it to its own adress range again. There might occur a difference regarding the data so it might me necessary to load some new data afterwards, but that is different problem.
The current idea is to serialize all Objects (could be about 1-2 Gigabyte) with Apache Thrift, and write them into shared memory. With Thrift the data is more or less ordered, so creating the objects anew is possibly easier (not sure here).
My Question is:
- Does it even make sense to consider shared memory in this scenario. I've read a lot stuff about in the last few days, and for now I don't see big disadvantages (except if the application crashes, in this case I've to read from database again). On the other hand I don't know how to really implement this functionality (as I'm no experienced Developer)
- Should I aim for Boost::Interproces, considering even memory mappable files, or stay with the traditional shmat (and stuff..)?
- I guess 1-2 Gigabyte shared memory will be necessary. This amount is only needed in the gap between application shutdown and restart. Will the sheer amount of needed shared memory be a problem (all examples I found just used a few Bytes or Kilobytes)
The application that I ported from 32 bit linux to 64 bit linux is crashing due to unknown memory corruption Also some time teh address is printed in 32 bit only as below
whats wrong with this code, I'm trying to parse a .js file and replace all the ";" with "; " i.e add a new line after each ";". So I load the file into a char[] buffer then assign a string to this contents of this buffer. Then loop char by char through using an iterator and check for a ";", if found use replace. So int i gets to about 85898 then crashes with unknown error, 'i' should reach about 175653. It does work up till it crashes. And, is this not a simpler way to load a file into a buffer, there is in C.
Ive narrowed down my crashing problem ( using printf's ) to a malloc call I had to use printf's because when i ran the program in Codeblocks debugging mode, it did not crash and ran fine, but when i ran it normally, it would crash, giving me this error:
fatal signal segmentation fault (sdl parachute deployed)
Inside my code, I created a malloce function that checks malloc for me ( so i dont have to do it )
I have a function such that one of its parameters is a 2D array of type int. The parameter is defined as follows:
[code] int topoGraph [][MAX_VERTICES] [code]
However, the following code snippet from the body of the function crashes at the specified line:
Code : if( counter >= 4 && !adjMatrixAlreadySet) { if( edgeCost == 10 ) { topoGraph[srcVertex][dstVertex] = 1; <<<<<---------- The point of crash } else if( edgeCost == 100000 )//restricted link { topoGraph[srcVertex][dstVertex] = edgeCost;
[code]....
It seems like there is an undefined behaviour at the specified point of crash since it crashes with different values of srcVertex and dstVertex each time I run it.
On a project I'm working on, I need to update many QLabels very quickly. Each label needs to be updated at about 20 to 50 hertz and there can be over 50 labels at any given time. The problem I'm having is after running the program for about a minute, the labels freeze and the whole program crashes about 10 seconds later. If I comment out the setText() and setNum() calls and reroute the outputs to the console, it runs fine and never crashes. Why does calling SetText() and setNum() so quickly cause the program to crash and how can I prevent this?
I am new to C. I've been trying to use C to code some statistical functions originally coded in R. I've encountered an interesting phenomenon. In the function foo1, I declared the array v1v2b using an actual value 1999000. The function runs fine when I call it in R.
Code: void foo1(double *x, double *y, int *nsamp){ int i, j, k, oper=2, l; double* v1v2=malloc(sizeof(double)*((*nsamp)*(*nsamp-1)/2 + 1)); outer_pos(x, y, nsamp, &v1v2[0]); double v1v2b[1999000]; //<-------HERE for(i=1; i<= 1999000]; i++){ v1v2b[i-1]=1; } }
However, in foo2, I first create an integer variable called index, and store the value 1999000 in it. I then use it to initialize the same array. When I tried calling this function in R, it either led to a stack overflow error, or completely crashed R.
Code: void foo2(double *x, double *y, int *nsamp){ int i, j, k, oper=2, l; double* v1v2=malloc(sizeof(double)*((*nsamp)*(*nsamp-1)/2 + 1));
I have a class which dynamically allocates memory for three data arrays, and as such in the destructor I told it to delete those data arrays.
However, when I've created a new class, and inherited the previous class - it will always crash AFTER running the program, unless I don't have the previous destructor present.
my program crash when it try to assign the return value of the function to the local value. extract function does return correct value, but it just crash when done executing.
What happens if I make a server application using tcp protocol and then establish connection with a client application but the server crash and then the client send data. Will the data be lost or the system will continue trying to send it?
I want to create an application that starts an application and passes input to that application. I know how to start a process using the classes in System.Diagnostics, but I don't know how to pass data to the process.
For example, and this is just an example, I would like to be able to automatically start an application that requires a username and password and automatically enter the username and password. Of course, that might open the door to security vulnerabilities, but that's not the point of the exercise.
How to implement the functionality I described? Is there a general way to go about doing this or does it depend entirely on the idiosyncrasies of the application in question?
#include <stdio.h> int main(void) { //2D Array int array[2][2]; int number = 1; }
[code]....
The array is not filled incorrectly for some reason, more specifically the first row.The first two cycles of the for loop seem to work correctly. One if the bugs seems to occur on the third. when array[0][2] is filled with number 7, for some reason array[1][0] changes it value to 7 as well.
I need to do an equivalent of kill -11 <pid>(which is in unix) in windows.
I need to crash a process with SEGV so that it would dump core in windows. Is there any tool by which we can do this . Also is there any sample code through which we can achieve this .
In windows we have taskill which only terminates a process , but is unable to send a signal like SEGV to the process upon which it would terminate and dump core .
I'm writing a program with a class containing a private std::vector<bool>. I chose bool because the vector represents a 2D array (think grid) and I only need 2 states per cell. I kept it one-dimensional as this hardly complicates things.
My problem is that I don't know how to initialize the vector, i.e. fill it with 0's.
The grid's resolution is not known at compile time, so I imagine I have to set the size (and content) of the vector in the class constructor.
Here's what I have tried among several things:
Code: World::World(const u_short worldsize) { grid.reserve(worldsize * worldsize); // grid is the private vector; square dimensions. std::fill(grid.begin(), grid.end(), 0); std::cout << grid.size(); } The output is 0. Only std::vector::push_back seems to have an effect on size(), but judging by its description, it doesn't look like the right candidate to populate a vector with zeros. Correct me if I'm wrong.
Frankly I expected line 3 to set the vector's size.
Code: int arr2d[rows][columns] ; // Not valid syntax of course ... let be arr2d rows * columns size for(int i=0; i<rows; i++) for(int j=0; j<columns; j++) arr2d[rows][columns] = some_value;
What is the complexity? I believe O(n) and not O(n^2) on this case because if you have 3*3 size you would put 9 elements (from 9 elements input of course)... for each input you have one insertion and that is the meaning. Same as 4*4 size 16 input times 16 insertions .. or 5*5 and so forth...
How to fill a vector with structs that are read in from a separate file. Each line in the file would read for example "Doe John M 26" for the name of the person, gender and age. I just need to get pointed in the right direction so I can get this started.
I am having a trivial trouble on how to create three different arrays from a text file. I am a beginner in C++. I have a .txt file containing a string of 'float' values as below:
0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3
//----------------------
Now, I want to make three arrays, p1[], p2[], and p3[] from them, so that p1[] has elements from line: 1, 4, 7, ..., p2[] has elements from line: 2, 5, 8, .., and p3[] has elements from line: 3, 6, 9,... of the .txt file.
My original file has a huge amount of data, so I would have to use a loop, but I cannot think of a way to fill my arrays as described.