Thread: Intentional memory leak?

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    22

    Intentional memory leak?

    Grumble.... I've got failing ram. I was thinking that as a stop gap solution (until I can afford a new dimm) would be to write a program that sits in the background eating up the bad portions of my memory thereby preventing other programs from accessing it.

    Having said that I would be a big help if someone could let me know how to do two things...

    1) How do I make a array that takes up a specific range of memory addresses?

    2)How would prevent my program from being paged out to the swap file?

    If anyone can help me with this you have my thanks.

  2. #2
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Allocating a block of memory with given size is not a big deal: you only have to do a new( sizeOfMemoryToBeAllocated ) - e.g. allocating memory for a char array of size 50000 would occupy 50000 bytes on the heap. Using the addressOf operator & you can even obtain the offset where this block starts, so you could manage your heap, without access to other memory segments than those assigned for your program.

    Experimenting with allocation of more and more memory might help, but you might need to allocate too much...

    AFAIK there's no way to guarantee that your process has access to a given memory range, at least not under operating systems which restrict the accessible memory space.

    Preventing the OS from swapping the memory to disk seems to be also hard to accomplish. Buying new DIMMs would be a "cleaner" sollution, however if someone gots an idea, I'd be also interested!

    P.s.
    Edited - more details
    Last edited by Carlos; 03-25-2004 at 06:19 AM.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    22
    Yeah, I know how to do the dynamic memory allocation thing...

    I've got a 512mb ddr dimm with bad adresses around the 196-197mb range and the 442-443mb range.

    I was hoping there was some easy way to just make 2 1mb arrays and tell them to live in those locations in memory.

    Memory tests have been consitent for two months now and don't show any signs of getting worse, so I was thinking maybe I could make it live a bit longer. Guess I'll just have to live with intermittent BSODs for a while.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    44

    suggestion

    i have a suggestion first you figure out exactly which address that the memory is faulty then you then you create the pointers it should look something like this
    Code:
    for(var=beginaddr;beginaddr <= endaddr;beginaddr++){
    pointer=beginaddr;
    }
    the only problem there is you would need some sort of loop that would generate pointers parralel with this loop so that you have pointers to fill the space and i dont know if you can point to specific addresses ok well i dont think that helped but what ever

  5. #5
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    You can only do that if the Operating System lets you. Otherwise you'll get a protection fault when you try to access it. I think?
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  6. #6
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Originally posted by HybridM
    You can only do that if the Operating System lets you. Otherwise you'll get a protection fault when you try to access it. I think?
    That's the point. IMHO - as I've written before - such workarounds can not be applied with OS-es like Windows or Linux.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The most surely can not. Your program neither has any knowledge of swap space nor of physical memory. It has its own virtual address range, but the mapping is up to the memory manager, and you'll never see it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Since you mentioned BSOD, I guess you're using windows.
    Shock and AWE
    My first attempt would go something like this...
    Find out the basic page size, then allocate as many physical pages as you can. Free all the ones which do not lie in the physical RAM which is bad.
    Then goto sleep.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Jul 2003
    Posts
    22
    Well thank's for all the suggestions... I had an idea though, in windows 98 it was possible to limit the amount of physical memory used through the msconfig applet. Does anyone know if there's a similar setting in Win2k? Been looking through my system files and applets and so far a I haven't found anything.


    EDIT: I just followed your "shock and awe" link and that sounds exactly like what I was looking for... Thank's Salem.
    Last edited by axlton; 03-26-2004 at 01:18 PM.

  10. #10
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The AllocateUserPhysicalPages(as suggested by Salem) method may work if you can figure out how to map the page frame numbers to the memory that is causing you trouble.

    Alternatively, there is a sample in the ddk "mapmem" that may be viable.

    Demonstrates how to map physical memory, as well as device adapter memory, into a user-mode process address space.

  11. #11
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    uhmm... I though RAM was allocated randomly throughout the chip, which is why when you have bad ram you usually have to go to quite a bit of trouble to actually find it. saying between xxx and xxx doesnt matter as the actual physical location is not known.

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You could always just buy more RAM and save all the messing around! If you can't afford 512mb, you could always just buy 256mb for now.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    Registered User
    Join Date
    Jul 2003
    Posts
    22
    Originally posted by Hammer
    You could always just buy more RAM and save all the messing around! If you can't afford 512mb, you could always just buy 256mb for now.

    I could but I also thought it would be an interesting programming project aside from that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leak in this case?
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 03-22-2008, 05:05 AM
  2. memory leak in the code?
    By George2 in forum C++ Programming
    Replies: 20
    Last Post: 01-13-2008, 06:50 AM
  3. Is this code memory leak free? ---> POSIX Threads
    By avalanche333 in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2007, 03:19 PM
  4. Any Memory Leak Checking Tool?
    By George2 in forum C Programming
    Replies: 4
    Last Post: 06-21-2006, 11:02 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM