Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

malloc/new behavior 1

Status
Not open for further replies.

psemianonymous

Programmer
Dec 2, 2002
1,877
US
I have a problem. The following line produces the error "First-chance exception in lt.exe (NTDLL.DLL): 0xC0000005: Access Violation." when I'm in debug mode.

The code is:
Code:
	cout << "sizeof sizeof parseTableRow_t * MAX_REASONABLE_PARSE_TABLE_ROWS" << endl;
	cout << sizeof parseTableRow_t << "       " << MAX_REASONABLE_PARSE_TABLE_ROWS << "       " << sizeof parseTableRow_t * MAX_REASONABLE_PARSE_TABLE_ROWS << endl;
	//table = (parseTableRow_t *)malloc(sizeof parseTableRow_t * MAX_REASONABLE_PARSE_TABLE_ROWS);
	[red]table = new parseTableRow_t[MAX_REASONABLE_PARSE_TABLE_ROWS];[/red]


The relevant output (if this helps you) is:
[tt]sizeof sizeof parseTableRow_t * MAX_REASONABLE_PARSE_TABLE_ROWS
16 82 1312
[/tt]


Now. If I change my constant MAX_REASONABLE_PARSE_TABLE_ROWS to something small, like "10", then this code works. But the above failed, as well as my original code, which had the "MAX" constant set to 400. Is this a size issue? Am I not allowed to allocate large chunks of memory?

By the way, table is a pointer to the "parseTableRow_t" struct. I'm using MSVC6.


Pete
 
Oh yeah. I changed the new call to a malloc() call, with the same exact result. Thus it's shown above, commented out.
 
I forgot to mention. yeah, I'm running in DEBUG mode, stepping through the program, and it doesn't instantly terminate the program. But, it doesn't allocate the memory, either.

Any help/workaround/head-smackingly obvious pointers?
 
> Am I not allowed to allocate large chunks of memory?
1300 bytes is a drop in the ocean.

Your problem is likely elsewhere in your code. Most dynamic memory problems go un-noticed at the moment the mistake is made, and its only later on when you try another dynamic memory operation (either new or delete) that it all goes wrong.

You might want to check out this link to help you locate where the problem occured (or at least get a better idea).

--
 
Thanks for the link. I'm checking it, and I'll post back if something interesting turns up.


Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top