Bult-in array of objects

From: X. (steamroller1922_at_yahoo.com)
Date: 12/31/04


Date: 31 Dec 2004 07:10:04 -0800

Hi,

There's been a discussion here on a similar topic that I'd like to
push a step further.
Suppose I get a class S having constructors:
  S(int n) - allocates n bytes of memory
  S() - allocates nothing
  and a copy constructor,copy assigment op. and so on.

I intend to declare a table of structures that contain (among other
things)objects of S with some memory allocated. When I simple-minded
code something like this:
   struct {
      S field1(20); //error here
      ...
   } x[100];

then my compiler insists to use default constructor which doesn't
allocate anything. And all my attempts to apply some object oriented
programming like:
   class X {
      S field1;
      ...
      X(int n): field1(n) {}
   };

   X x[100];
   for(i...)
   { X xxx(20); //to get space for xxx
      x[i] = xxx; //hope the memory chunk will be assigned to x[i]
   }
fall short because the operator= doesn't allocate memory, and flags an
error. In other words, it can't copy an object to an "empty" one).

Well, I could use vector<> or another container (or even overload
operators of S yet I'd prefer not doing so) but this thought's
torturing me in this New Year Eve: how to use a built-in tables to
keep objects? Books (ex.Lippmann's one) claim that's possible but give
no hints.

Happy New Year to those who will reply to my post and those who won't.
X.



Relevant Pages

  • Re: Bult-in array of objects
    ... Shoot me where I sit if that's completely off the mark. ... > Suppose I get a class S having constructors: ... > S- allocates n bytes of memory ... > things)objects of S with some memory allocated. ...
    (comp.lang.cpp)
  • Re: Why cant value types have initializers?
    ... It says that structs cannot have ... Which is something that CLR, ... simply allocates a block of memory large enough, ... C++ rules for when constructors and destructors run can get ...
    (microsoft.public.dotnet.framework)
  • Re: Framework 2.0 array redim unsatisfactory performance
    ... implementation details of Redim, Redim Preserve, and List. ... significantly higher object allocated overhead then List. ... ReDim simply allocates a new ... but I do not even attempt to test its memory ...
    (microsoft.public.dotnet.languages.vb)
  • Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
    ... This is an array of pointers to buffers that get set up ... the driver allocates the buffers (via an internal allocation ... routine from its own block of reserved memory). ... So I can map ...
    (microsoft.public.windowsce.platbuilder)
  • Re: CE6.0 Driver Pointer Marshalling - passing pointers out only?
    ... I've got a pretty complex driver I'm porting up at the moment ... This is an array of pointers to buffers that get set up ... the driver allocates the buffers (via an internal allocation ... routine from its own block of reserved memory). ...
    (microsoft.public.windowsce.platbuilder)