a 20-line random walk [heap corrupted]

The Partridge Family were neither partridges nor a family. Discuss.
Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: a 20-line random walk

Post by Clodi » December 23rd, 2014, 4:09 pm

edit:

:mrgreen:

Yes, you were right. rand() is not random. Your random generator works a LOT better! It's actually random. You start several statistically indipendent random walks and you obtain a slow decrease. You look at a single random walk and it will fluctuate about zero with fluctuations that are consistent with the distance traveled. Perfect. Now I can carry on working thanks to you guys.
Attachments
lux random.jpg
(30.44 KiB) Not downloaded yet

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: a 20-line random walk [heap corrupted]

Post by Clodi » December 30th, 2014, 4:35 pm

Perfect..
I think that I have just ruined my PC forever. I made a memory leak and forgot about it. Now everytime I run my program, I get weird errors. The code pauses and I get debug assertion saying that the code has triggered a break point.

Code: Select all

Windows has triggered a breakpoint in KMC.exe.

This may be due to a corruption of the heap, which indicates a bug in KMC.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while KMC.exe has focus.

The output window may have more diagnostic information.
Then when I go and look at the problem I see this

Code: Select all

extern "C" _CRTIMP int __cdecl _CrtIsValidHeapPointer(
        const void * pUserData
        )
{
        if (!pUserData)
            return FALSE;

        if (!_CrtIsValidPointer(pHdr(pUserData), sizeof(_CrtMemBlockHeader), FALSE))
            return FALSE;

        return HeapValidate( _crtheap, 0, pHdr(pUserData) );
}
No idea what it means. Does anyone know?

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: a 20-line random walk [heap corrupted]

Post by albinopapa » December 30th, 2014, 6:25 pm

The output window may have more diagnostic information.

Have you checked here ^
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: a 20-line random walk [heap corrupted]

Post by Clodi » December 30th, 2014, 6:44 pm

mmm.. the thing is.. what is the output window?
the console window itself is pitch black and the VS window is pointing to those lines of code that I posted. Not sure where to look at.

ALSO, I just run the code in another computer and it runs perfectly. Got my results and I am happy and everything. Just, I don't know how bad I screwed things up when I was not releasing and deleting my pointers. Not sure how to get that memory back :( on stack overflow they say it doesn't even matter because modern machines clean up everything anyway. :?

:?: :?: :?: :?:

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: a 20-line random walk [heap corrupted]

Post by albinopapa » January 2nd, 2015, 1:42 am

When you compile the program the output window is at the bottom of the VS window. Anyway it sounds like you know where it is anyway. I would run in debug mode and set a few break points you think it might be and narrow down where the error is being caused. You can also set a break point and press F10 or F11 to go line by line and wait for the error.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Clodi
Posts: 175
Joined: November 18th, 2012, 7:47 pm

Re: a 20-line random walk [heap corrupted]

Post by Clodi » January 4th, 2015, 12:08 am

OK. Thanks, I'll try that.
Is the memory that you lose while not deleting the pointers coming back after you go back to the code and delete them?

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: a 20-line random walk [heap corrupted]

Post by LuisR14 » January 5th, 2015, 2:06 am

it returns when the app exits, can always restart pc in case lol
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: a 20-line random walk [heap corrupted]

Post by albinopapa » January 5th, 2015, 4:33 am

I've always wondered about memory leaks myself. I use to use a program that you could watch the memory depleting in the task manager while the computer was running, but it's been so long that I can't remember if the memory was reclaimed when I exited or not. Pretty sure it did, but again I just can't remember. I suppose it could be tested by just allocating a couple gigs of ram and then exit the program without any deallocating and see what happens.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: a 20-line random walk [heap corrupted]

Post by MrGodin » January 6th, 2015, 1:25 am

If you use C# and create a "new" instance of an object, it deallocates the memory for you doesn't It. I have been exploring c# and all the examples i have seen, none calls for deallocation ... A tad off topic , but is that so ?, C# handles memory management for you ? . If so, that just makes programming lazy lol ... ohhh wait, programmers are lazy, cut'n paste, cut 'n paste ... lalala ...... hahahaha
Peace Out
Curiosity killed the cat, satisfaction brought him back

cameron
Posts: 794
Joined: June 26th, 2012, 5:38 pm
Location: USA

Re: a 20-line random walk [heap corrupted]

Post by cameron » January 6th, 2015, 1:52 am

After using c++ for a few years, I must say that I really dislike c#. Dynamic memory allocation I find to be a joke. First off they have their "garbage collector" that automaticly frees all memory for you as it goes out of scope. Also, it moves all your memory around so an array is no longer a pointer. I feel it creates more pain than productivity if you know what your doing. One thing that c# is nice for is .net framework and built in functions or "methods" if you use c# terminology.
Computer too slow? Consider running a VM on your toaster.

Post Reply