News, tips, advice, support for Windows, Office, PCs & more. Tech help. No bull. We're community supported by donations from our Plus Members, and proud of it
Home icon Home icon Home icon Email icon RSS icon
  • Free memory

    This topic contains 5 replies, has 2 voices, and was last updated by  WSAndyAinscow 18 years, 7 months ago.

    • Author
      Posts
    • #352325 Reply

      WSBart
      AskWoody Lounger

      Hi everybody,

      From VBA I call a couple of functions from a DLL written in C++.
      This DLL also contains a (hidden) function with a private variable.

      The functions from the DLL are declared in VBA and a call them using the aliases defined in the declare.
      After calling the functions the private variable is set and will keep it’s value.

      Because I just call the function, no object is defined in VBA. In memory there will be an object defined (containing the value of the private variable for instance).

      Is there a way to free that memory from VBA code?
      I can not set the object to nothing, because I do not have the object in VB, I just call the function!

    • #512195 Reply

      WSAndyAinscow
      AskWoody Lounger

      I am a little unclear what you want. Do you want to unload the dll from memory? or just set the value of the variable to it’s default?
      What is the variable? In other words is it a real problem? An int takes very little space up. A 10MB Bitmap is very different and then I understand your desire to remove it.
      Can you recode the dll? By that if it is a real memory hogging variable have it as a pointer in the dll and use new and delete to create/destroy the real hog when it is required.

      • #512212 Reply

        WSBart
        AskWoody Lounger

        Hi Andy,

        Thanks for the reaction.
        Unloading the DLL is no option, then I have to reload it again about 50.000 times.
        I just want to reset the static.
        I solved it the moment by adding a new function to the dll, initiate.
        There must be a better way, once I will find it…..

        • #512241 Reply

          WSAndyAinscow
          AskWoody Lounger

          Hi Bart,

          How about calling the function with a flag to re-initialise the variable eg. CallFunction(ResetVariableToDefault) and test ‘ResetVariableToDefault’ inside the dll.

          Out of interest why do you want a static variable in the dll? I’ve made a number of dll’s that are called from Access, maybe you know something I should know.

          • #512298 Reply

            WSBart
            AskWoody Lounger

            Hi Andy,

            Queriosity is a great quality, you can learn a lot…
            I put several function in the DLL, which are called in quite a complex batch process from VB. I use some statics to store data in the DLL that is not needed in VB. Working like this prevents sending that data from the DLL to VB and back without using it in VB.
            Because the batch proces is processing a lot of transactions it is no option to remove the DLL from memory and bringing it up again for each transaction.
            And yes, I already programmed an initialise function in the DLL, I did not see another way (although I still think there must be one).

            Thanks for the help.

            • #512393 Reply

              WSAndyAinscow
              AskWoody Lounger

              I guessed that was the reason for the static. I’d do a very similar thing as I can’t think of another other viable method.

    Please follow the -Lounge Rules- no personal attacks, no swearing, and politics/religion are relegated to the Rants forum.

    Reply To: Free memory

    You can use BBCodes to format your content.
    Your account can't use Advanced BBCodes, they will be stripped before saving.