| | |
Access violation in C
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Solved Threads: 0
Hi
During writing a code, I need to define dynamic arrays several times, so I wrote the following simple function for defining a double 1D array:
The function works well for more than 20 calling but suddenly it gives the following error:
“Unhandled exception in a.exe: Access Violation"
I checked the code several times and I'm quite sure that error is happened in calling this function. If there was any problem in memory, I expected to receive memory error message but now, I don't know what is wrong with code. Would you please help me?
During writing a code, I need to define dynamic arrays several times, so I wrote the following simple function for defining a double 1D array:
c Syntax (Toggle Plain Text)
/*---------------------------------------------------------------------------- Function for Difining 1-D Dynaimcs Arrays for Storing Double Values ------------------------------------------------------------------------------*/ double *allocation_1d_double(int size) { double *array; if ( (array = (double *)malloc(size*sizeof(double)) ) == NULL ) { printf("\nError, memory not allocated.\n"); exit(1); } return array; }
The function works well for more than 20 calling but suddenly it gives the following error:
“Unhandled exception in a.exe: Access Violation"
I checked the code several times and I'm quite sure that error is happened in calling this function. If there was any problem in memory, I expected to receive memory error message but now, I don't know what is wrong with code. Would you please help me?
Last edited by WaltP; Apr 11th, 2007 at 3:19 am. Reason: Added CODE tags -- you actually typed right over what they are when you entered this post...
something is probably corrupting the memory pool some place else in your program and that's a difficult problem to find. If you have a large progrm I would start by commenting out large blocks of code until the problem goes away. That at least narrows down the search.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Solved Threads: 0
Thanks for the guide.
The code is so large and for other size of input data this error is occurred in some other allocation part. so It seems that I have memory problem. My compiler is Visual C++ v.6.0 and my pc has32 bit processor.
I think that I should change the code in the way that I can free some of the arrays after using so that I will have some free memory space for writing rest of the code. What is your idea? Does using 64 bit processor or other compilers have effect? Please advise.
BR,
Ahad
The code is so large and for other size of input data this error is occurred in some other allocation part. so It seems that I have memory problem. My compiler is Visual C++ v.6.0 and my pc has32 bit processor.
I think that I should change the code in the way that I can free some of the arrays after using so that I will have some free memory space for writing rest of the code. What is your idea? Does using 64 bit processor or other compilers have effect? Please advise.
BR,
Ahad
>>Does using 64 bit processor or other compilers have effect?
The compiler and processor are not relevent to memory leaks. Offhand I'd say your program has buffer overruns somewhere.
The compiler and processor are not relevent to memory leaks. Offhand I'd say your program has buffer overruns somewhere.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Access violation reading location 0xcccccccc (C++)
- access violation at address 0055E531 in module (Windows NT / 2000 / XP)
- Unhandled exception in IEXPLORER.EXE (SHDOCVW.DLL): 0xC0000005: Access Violation (Web Browsers)
- access violation at 0x00000024 (Windows NT / 2000 / XP)
- How do I access variables in my queue? (C++)
- Access Violation (Segmentation Fault) + atol (C++)
- unhandaled exception,0X000005:access violation (C)
- Accession Violation message on installation of program (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: boot?
- Next Thread: Function declaration error
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez graphics gtkgcurlcompiling gtkwinlinux hardware highest homework i/o ide inches initialization intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives loopinsideloop. lowest match matrix microsoft motherboard mqqueue multi mysql oddnumber odf open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






