CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Posts
    2

    Question Loading DLL's at custom base address

    I've got a funny situation in which a program runs out of memory too early. With too early I mean the malloc() and new() are failing because they can't allocate memory while there is still plenty.
    The problem is that there is no big enough chunk of memory available. The app requests 300 meg, while there the largest chunk available is 250 f.i.

    The cause of this memory "fragmentation" are a couple of DLL's with a bad base address. Most of these DLL's are shipped together with the application so I can use the REBASE tool to give them a sensible address.

    But I've got one left... OPENGL32.DLL has a base address of 0x5ED0000 and is a system DLL so I can't modify this one.
    I can of course copy this file, rebase it, and put it next to the executable.

    But that's not what I want to do. Because this way I'll be missing out on updates (via service packs f.i.).

    The "beautifull" way would be to "tell" the loader that it shouldn't use the base address but load it somewhere else.

    In other words, I want to force a relocation of a DLL.

    Has any of you done this before ?

  2. #2
    Join Date
    Nov 2000
    Location
    Munich, Germany
    Posts
    161
    Actually, I think you will have further DLLs on your customers computers which will cause trouble, not only OPENGL32.dll. PGP Plugins for example love to pop into your applications address space by some hook from system32.dll.
    Thus I would recommend doing it the other way around: Convert your executable from an exe to a DLL. Afterwards, write a simple loader, which first allocates the 300M memory chunk and afterwards loads dynamically your "DLL" application. Thus all rebasing would be done by the operating system afterwards.
    BTW: You should take a look at your programs memory consumption - 300 Meg in one large chunk - there must be something wrong with your applications design!?
    The Saviour of the World is a Penguin and Linus Torvalds is his Prophet.

  3. #3
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Loading DLL's at custom base address

    Originally posted by KarelBijl
    The "beautifull" way would be to "tell" the loader that it shouldn't use the base address but load it somewhere else.

    In other words, I want to force a relocation of a DLL.

    Has any of you done this before ?
    No. I haven't. Nor I tried to understand your problem. But just looking at this question, I beleive there is a way ( which of course I haven't tried at all )

    If you are using VC++ IDE, in your project settings, go to Link tab, select category as Output. Here you have an option to specify the base address. You could try it. But probably this is not an option for you since you want to change the base address of OpenGL, right ?

  4. #4
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    There was a similar question about a month ago where the problem was difficulty allocating 300 MB. In that situation, the allocatin was being used for a very large image. Responses in that thread suggested redesigning the application.

    300 MB is a huge amount of memory. There was a time when that amount of physical memory would be very expensive yet whatever you are doing, it was done then too. Hardware is so cheap compared to the recent past that it is certainly best to let it do the work instead of us but in this situation it is probably relatively easy to process the data without loading all of it into memory at once.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  5. #5
    Join Date
    Apr 2004
    Posts
    2
    I agree that preventing the allocation of a 300 meg chunk sounds like the obvious solution.

    But this not really an option. Actually the 300 meg in one go was introduced for speed improvements. Only on windows 32 bit I have this problem with DLL in the wrong place.

    I've thought of claiming the base address of OPENGL32.dll .. I wonder where the loader will put it then.

  6. #6
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by KarelBijl
    But this not really an option.
    Sure it is.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured