1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Dynamic addition of new objects (of some class) to an array.

Discussion in 'MFC' started by danwes, Sep 3, 2010.

  1. danwes

    danwes New Member

    Joined:
    Sep 3, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello,
    I am very new to this forum, I hope I ended up right.
    I have the following problem. I am extracting some image patches from a video by convolving the images with some filter. Each extracted patch (i.e. image region) is defined in the code as an object of class 'Patch' which has some attributes, for instance its position in the image, which frame it was extracted from, what colors it has etc. The problem is that I don't know beforehand how many patches my filter will extract from, say, 50 frames of a video sequence. I was thinking about defining an array of pointers to such objects, but here I don't know the size of such array. Is there any way I could firstly initilize such array for 100 objects and then, if more than 100 patches come, increase array's size on-the-fly? Kind of as one could do with vector container objects (using push_back()).
    Another issue though is, that even though I could firstly initilize the array for 100 objects with the 'new' operator, then afterwards, could I create different sizes for N-dimensional tables, which are actually other objects defined within the class 'Patch'? I mean here, for example, I have an i-th object of class 'Patch' whose address is in the array, and this object has an attribute called Matrix of class, say, Table. One time, for that 'Patch' object, I would like to define Matrix as an N-dim vector, and another time in the code, define Matrix as NxM matrix. This allocates different memory size, of course. So my second question is, how can the compiler know how much memory to allocate for all the objects in the array of 100 elements, when each such object could be called within the program with an Table attribute of varying size?
    Ufff, that was pretty hard to explain :)
    Could someone help, please? I would really appreciate it. I don't have any experience with such type of things. If needed, I could also explain these 2 problems that I have in other words, or in more detail.
    Thx in advance!
    Daniel
     

Share This Page