Re: ATL/COM memory management

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jag Man (Jag_Man653R-E-MOVE_at_hotmail.com)
Date: 05/10/04

  • Next message: Jag Man: "Re: ATL/COM memory management"
    Date: Mon, 10 May 2004 08:40:45 -0700
    
    

    Simon,

    > > Dim myObj As myClass(10)
    > > in the declarations section of a Module, but it is not accepted.
    >
    > No, the client will create ten instances of the object by making ten calls
    > to the class factory.

    I was not trying to indicate 10 instances of the class. Rather, I was trying
    to say
    one instance of the class, but with that instance having a member array
    allocated
    to be size 10.

    > > If it can't be done this way, how does one get the size to allocate some
    > > form of an array
    > > in a constructor or FinalConstruct()?
    >
    > I'm not sure what you are trying to do here. The array (or a
    > pointer/reference to it) should be a *member* of the coclass, which then
    > defines indexed properties to access it.
    >If desirable, make a separate
    > "container" class that just wraps the array, and in your other class
    define
    > properties which are typed to this separate class. (This also has the
    > advantage that the separate class is likely to me more reusable, and then
    > you can also define the NewEnum property on it to get "for each" style
    > enumeration.

    Yes, the array is to be a class member. Clearly, that array has to have
    memory allocated
    for it. In C++ one would make the class member a pointer, then allocate in
    the constructor
    using a parameter:

    myClass::myClass(int size)
    {
          n = size;
         theArray = new long[n];
    }

    so that to instantiate one would write:

    myClass object(10); // creating one instance of myClass having an array size
    of 10.

    I am trying to do the equivalent of this in a COM to be used in VBA. What I
    am missing somehow
    is how the VBA tells the COM what size of array will be needed.

    Thanks for your patience!

    Ed


  • Next message: Jag Man: "Re: ATL/COM memory management"

    Relevant Pages

    • Re: Cons cell archaic!?
      ... from s-expression or XML or other syntax you keep the bloated array ... For using vectors to emulate lists that ... Allocate 2, move 1 element: ... What do you think of that algorithm? ...
      (comp.lang.lisp)
    • Storing/Retrieving TYPEs with ALLOCATABLE components (TR) (long)
      ... tBrd, including array descriptor of tEn )). ... Without previous DEALLOCATE, the allocate line fails at run time with message ... the fact that I'm loading an invalid descriptor tBrd%tEn from the file... ... status (which is not possible according to Standard, but then BINARY files ...
      (comp.lang.fortran)
    • Re: Storing the size of an array in the structure itself
      ... >> I think every C programmer can relate to the frustrations that malloc ... >> the size of an array must be stored separately to be a nightmare. ... is anything more than just that - a chunk of memory. ... > Otherwise you couldn't tell it how much to allocate. ...
      (comp.lang.c)
    • Re: Interoperability with C
      ... have a procedure return a variable size array that you didn't allocate ... Then allocate an array ... with 'sufficient' buffer and the routine stores the data. ...
      (comp.lang.fortran)
    • determining available space for Float32, for instance
      ... I am looking for a way to determine the maxium array size I can allocate ... We do not want a solution that requires recompiling Python, ... agents may be households that choose a new gridcell to live in. ... Each attribute of a dataset has such a 2D array. ...
      (comp.lang.python)