473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Issues w/CRT on program exit?

Doing some work on the ol' memory manager this evening and recently I've been having read access violations occur after the actual program exit. The problematic line appears as follows, it appears to have to do with the value passed from my main function:
Expand|Select|Wrap|Line Numbers
  1. mainret = _tmain(__argc, _targv, _tenviron);
  2.  
I'm no CRT expert, would anyone be able to give me some guidance as to what's going wrong here? I'm also having some difficulty figuring out a problem like this one would even occur. I can provide parts of my pool code upon request.

BTW I'm using MSVC2005.
Jun 18 '07 #1
2 2580
weaknessforcats
9,208 Expert Mod 8TB
mainret = _tmain(__argc, _targv, _tenviron);
If mainret is a return from _tmain(), then you are recursively calling your program. This probably continues until you blow the stack memory withall those _tmain() stack frames.

I need to see your _tmain() to see how you break the infinite recursion.
Jun 18 '07 #2
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     CMemoryPool testingPool(65536, 1024);
  4.     return 0;
  5. }
  6.  
Lovely, I know. Basic synopsis of what this is/means:
-I've obviously instantiated an instance of my memory pool class, the constructor there accepts two arguments: size of a block in the pool (64kb here) and the total number of blocks in the pool. (1024, for a grand total size of 64MB)

Constructor contents:
(It kind of butchered some of my formatting, sorry)
Expand|Select|Wrap|Line Numbers
  1. CMemoryPool::CMemoryPool(const size_t &_blockSize, const size_t &_defaultNumBlocksPerPage) : blockSize(_blockSize),                                                         defaultNumBlocksPerPage(_defaultNumBlocksPerPage), 
  2.                                         defaultPageTotalCapacity(blockSize*defaultNumBlocksPerPage),
  3.                                                         pageFirst(NULL), pageLast(NULL)
  4. {
  5.     cursorPtr = AllocateNewPage();
  6. }
  7.  
Essentially what happens there is that (obviously, I hope) cursorPtr, a general-purpose utility pointer used in ordering, searching/return and maintenance tasks gets set to the last pointer in the list of pages as a sort of safeguard and overhead reduction step. A new CMemoryPage class is created and then a new hunk of memory large enough to "contain" the number of blocks that you specified of the given size. (more on the quotation marks in a second)
Then the overall formatting and sectioning off of the physical page in memory begins. New 'block' objects are formed via regular new() commands, their individual constant pointers assigned to respective sections of the external block and finally everything is all set.

Page constructor code:
Expand|Select|Wrap|Line Numbers
  1. CMemoryPool::CMemoryPage::CMemoryPage(const size_t &_blockSize, const size_t &numBlocksInPage) : blockSize(_blockSize), 
  2.                                                                                                         numTotalBlocks(numBlocksInPage),
  3.                                                                                                         numFreeBlocks(numBlocksInPage)
  4. {
  5.     byte* pageLocation = (byte*)::operator new(blockSize*numBlocksInPage);    // allocate the correct amount of space-- size of a block times number of blocks
  6.     blockFirst = new CMemoryBlock(pageLocation);    // take care of the first block here so we don't have to spend cycles on ifs throughout the for loop
  7.     cursorBlock = blockFirst;
  8.     pageLocation+=blockSize;
  9.     for(size_t i=0; i<numBlocksInPage; pageLocation+=blockSize, i++)
  10.     {
  11.         cursorBlock->blockNext = new CMemoryBlock((void*)pageLocation);
  12.         cursorBlock = cursorBlock->blockNext;
  13.     }
  14.     page = (void*)pageLocation;    // and tell the page object where it lives
  15. }
  16.  
I actually think the problem is with the loop at the end. I believe the second block int the page might not ever be initialized XD
Will update that after further examination.

EDIT: well I did find some problems, but actually the second thing did appear to execute correctly. It would seem, however, that pageLocation has flat-out ignored my instruction to increment itself by blockSize, despite the fact that it is *NOT* a constant. Rather baffling.

EDIT 2: Got it working using a fancy setup of address-of operators on pageLocation[0] and all that fun stuff. Highly annoying to have to spend time figuring out how to do that >:\ Still getting the errors though, have moves on to troubleshooting other parts of the pool.
Jun 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Aliencat | last post by:
I'm having issues compiling php v4.2.2 on Redhat 9.0. The goal ultimately is to compile in mcrypt support, but that's a bit down the road from here. I've chased down the dependencies for the...
3
by: Phil IU Guy | last post by:
I am having 2 issues, both acting very randomly, and for the most part I dont get this message on most computers, but I have had a couple computers get either issue 1, or issue 2. Issue #1: I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
1
by: confusedprogrammer | last post by:
In the program below i need to get it, so that it will keep going through the program asks all the question and displays the results and goes back to the beginning if the user didn't select. After...
4
by: vaiism | last post by:
I have the following block of code which works, although if you call the function a second time through the menu defined elsewhere in the program there are some screwy (different combinations of the...
6
by: aureao4 | last post by:
I'm new to Java and programming. I'm trying to code a payroll program and continue getting errors. The program worked last week, this week I have to add set, get and a class. I've written the class...
1
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.