About Store Forum Documentation Contact
Donations:
227$/mo



Post Reply 
Meml container issues
Author Message
JonathonA Offline
Member

Post: #1
Meml container issues
Okay so I am having some issues with Meml containers; I have created a HashTable class with this container:

Code:
template<typename KeyType, typename DataType>
class HashTable
{
...
Memc<Meml<HashNode<KeyType, DataType>>> table;
}

And this is code I use to insert a new element into that table:

Code:
        void HashTable::Insert(KeyType key, DataType data)
        {
            int index = hashFunction( key ) % tableSize;

            HashNode<KeyType, DataType>& newNode = table[index].New();
            newNode.key = key;
            newNode.data = data;

            elementCount++;
        }

Here is the code causing the issue:

Code:
class AnimationSet
{
...
HashTable<Str, Str> anims;
}

class AnimationGroup
{
...
HashTable<Str, AnimationSet> sets;

The AnimationGroup::sets variable references another class that contains a HashTable and I get this compilation error as a result:

Code:
hash table.h(33) : error C2783: 'void EE::_Meml::operator =(EE::_Meml &)' : could not deduce template argument for 'UNUSED'
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\esenthelengine\memory\_meml.h(49) : see declaration of 'EE::_Meml::operator ='
1>        This diagnostic occurred in the compiler generated function 'EE::Meml<TYPE> &EE::Meml<TYPE>::operator =(EE::Meml<TYPE> &)'
1>        with
1>        [
1>            TYPE=HashNode<EE::Str,EE::Str>
1>        ]

I'm not sure how to get around this problem; Has anyone got any suggestions?
03-27-2012 12:55 AM
Visit this user's website Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #2
RE: Meml container issues
Appears to be the Meml NO_COPY_CONSTRUCTOR and this line from the Insert function:
Code:
newNode.data = data;
which I assume is trying to invoke it?
03-27-2012 11:52 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Meml container issues
I will add copy ctor for next sdk release
03-27-2012 12:02 PM
Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #4
RE: Meml container issues
Thank you very much; I wasn't sure if I should put in a feature request since it appeared to be a 'by design' feature.
03-27-2012 12:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #5
RE: Meml container issues
Just another quick question about containers, if I have this:

Code:
Memc<Meml<someCustomClass>> table;

And then I call:

Code:
table.del();

Does that do something like this?

Memc.del() -> Meml.del() -> ~someCustomClass?

Just having some memory leak issues when "someCustomClass" contains pointers. even if those pointers are deleted in ~someCustomClass() it still leaks memory on application exit.

Thanks for the help so far on all of this, it is much appreciated smile
03-29-2012 01:29 AM
Visit this user's website Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #6
RE: Meml container issues
Hmm so here is my code at the moment; it is pretty basic and I have removed all the parsing code since it would bloat this post way too much. The end goal is to be able to set up default animation sets (called AnimationGroups) for each race in-game and I can swap out memory addresses whenever I need to change sets based on game state.

Code:
// This function is called in Main.cpp to set up the extern AnimGroupsCache variable memory (see below)
Bool PrecacheAnimations(C Str& fileName)
{
   AnimGroupsCache.setNum(RACE_COUNT);
   // Parse XML file to identify which race it is for...
   AnimGroupsCache[RACE_ID].PopulateTable(xmlFile);
}

struct AnimationCache // Holds a list of animations for each group
{
    AnimationCache(void) { }
    AnimationCache(FileXml& file) { PopulateCache(file); }
    ~AnimationCache(void) { animations.del(); }

    void PopulateCache(FileXml& file)
        {
                // Create a dummy skeleton so we can get a reference to SkelAnim instances
                CSkeleton dummy;
                dummy.create(&Skeleton());

                // Parse all sub nodes (<Animation></Animation> tags) of <Group></Group> tags to get animation file names and for each sub node call the following line:
                animations.New() = dummy.findSkelAnim(file()); // Memory leak fun :D

                // Once parsing is complete clean up after our dummy
                dummy.del();
        }

        // Set of animations: idle, walk, run, etc
        Memc<SkelAnim*> animations;
};

class AnimationGroups // Holds collections of animations for each race
{
    public:
        AnimationGroups(void) : groupTable() { }
        AnimationGroups(unsigned int tableSize) : groupTable(tableSize, HashString)    { }
        ~AnimationGroups(void) { groupTable.del(); }

        void PopulateTable(FileXml& file)
                {
                         // Parse file for <Group></Group> tags, when found do the following:
                         groupTable.Insert(groupKey, AnimationCache(file));
                }

                AnimationCache* GetGroup(C Str& groupKey);

    private:
        HashTable<Str, AnimationCache> groupTable;    
};

// Holds an AnimationGroups instance for each race in-game.
extern Memc<AnimationGroups> AnimGroupsCache;

Code:
AnimGroupsCache.del()
is called in the ShutDown function for the application.



So the Memc<SkelAnim*> animations container even though animations.del() is called in ~AnimationCache() it is leaking and I can't figure out why at the moment. Every time I have tried to use pointers of any description in the above code it just leaks it.
(This post was last modified: 03-29-2012 02:44 PM by JonathonA.)
03-29-2012 12:40 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Meml container issues
(03-29-2012 01:29 AM)JonathonA Wrote:  Does that do something like this?

Memc.del() -> Meml.del() -> ~someCustomClass?
yes
03-29-2012 01:08 PM
Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #8
RE: Meml container issues
Thanks for the quick response; so what does .del() do when the elements of the memory container are pointers like this?

Code:
Memc<SkelAnim*> animations;

I did a quick test in Main.cpp that was similar to my other code that is leaking and still suffer with the same issue:

Code:
CSkeleton dummy;
dummy.create(&Skeleton());

Memc<SkelAnim*> table;
table.New() = &dummy.getSkelAnim("anim path here"); // leaky leaky

dummy.del();
table.del();

Hmm okay so this code doesn't appear to leak so I'll give it a shot with this code for now and see how I get on but its pretty awkward:

Code:
CSkeleton dummy;
dummy.create(&Skeleton());

Memc<SkelAnim*> table;
table.New() = &SkelAnim(Skeleton(), *Animations.get("anim path here")); // not so leaky leaky

//dummy.del(); no need to call this
table.del();

Biggest question is I am still not sure why using dummy.getSkelAnim or .findSkelAnim was causing a leak? Is it that SKelAnim doesn't have a copy/assignment operator defined so its just doing a shallow copy when I called table.New() = &dummy.getSkelAnim(...)?
(This post was last modified: 03-29-2012 01:59 PM by JonathonA.)
03-29-2012 01:31 PM
Visit this user's website Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #9
RE: Meml container issues
Hmm okay it didn't work when I tried applying it to my animation code from earlier.

This line called in AnimationGroups::PopulateTable:

Code:
groupTable.Insert(groupKey, AnimationCache(file));

which calls:

Code:
void Insert(KeyType key, DataType data)
        {
            int index = hashFunction( key ) % tableSize;

            HashNode<KeyType, DataType>& newNode = table[index].New();
            newNode.key = key;
            newNode.data = data;

            elementCount++;
        }

After the line newNode.data = data; the AnimationCache destructor is called, why is that happening? Destructor shouldn't be called until AnimGroupsCache.del() is called.
Only way around this destructor problem is giving the AnimationCache class a del() function, but I need Meml to invoke that when Meml.del() is called instead of ~AnimationCache().

Is that possible?
(This post was last modified: 03-29-2012 02:57 PM by JonathonA.)
03-29-2012 02:52 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Abril Offline
Member

Post: #10
RE: Meml container issues
(03-29-2012 01:31 PM)JonathonA Wrote:  Thanks for the quick response; so what does .del() do when the elements of the memory container are pointers like this?

Code:
Memc<SkelAnim*> animations;

It will not call delete on the pointers, if this is whta you were asking.
The memc is kinda similar to the vector class in STL, you should have a look at the STL documentation to get an idea.
Consider using smart pointers instaed of raw pointers to achieve that. Hope this helped...
03-29-2012 07:55 PM
Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #11
RE: Meml container issues
(03-29-2012 07:55 PM)Abril Wrote:  
(03-29-2012 01:31 PM)JonathonA Wrote:  Thanks for the quick response; so what does .del() do when the elements of the memory container are pointers like this?

Code:
Memc<SkelAnim*> animations;

It will not call delete on the pointers, if this is whta you were asking.
The memc is kinda similar to the vector class in STL, you should have a look at the STL documentation to get an idea.
Consider using smart pointers instaed of raw pointers to achieve that. Hope this helped...

Thank you abril I will check it out smile
03-29-2012 09:55 PM
Visit this user's website Find all posts by this user Quote this message in a reply
AndrewBGS Offline
Member

Post: #12
RE: Meml container issues
I'm having problems because of that NO_COPY_CONSTRUCTOR also, finally figured it out after hours of trying :|

So that change hasn't been implemented yet, has it?
I'm trying to get an object created out of the Memx container. Any idea as to when this will be possible? My work next is kinda depending on this.
04-23-2013 08:54 PM
Find all posts by this user Quote this message in a reply
Post Reply