jeudi 30 juin 2016

How Does Allocated Memory Get Freed In C++?

Let's say I have a header file, armorshop.h, containing a class definition, along with a corresponding .cpp for this header file.

My question is:

  1. How does allocated memory get freed in c++?
  2. Will allocatedmemory1, allocatedmemory2, allocatedmemory3, or allocatedmemory4 ever be freed on its own in each of these scenarios?
  3. Will these aformentioned allocatedmemories be redefined and cause an error in each of these scenarios?
  4. Do variables and classes, etc defined inside of a class definition get freed when they are not being used, and redefined when they are used again? Or do they get defined once and use up resources while not being used?

Thanks

//scenario 1
//armorshop.h
#ifndef __SFML__armorshop__
#define __SFML__armorshop__


class armorshop : public entity
{
public:

};

int allocatedmemory1;
sf::FloatRect allocatedmemory2;
class armorshop allocatedmemory3;
std::vector<armorshop> allocatedmemory4;

#endif

(question 3 clarification in relation to scenario 1:) If I #include "armorshop.h" multiple times will this cause an error

//scenario 2
//armorshop.cpp
int allocatedmemory1;
sf::FloatRect allocatedmemory2;
class armorshop allocatedmemory3;
std::vector<armorshop> allocatedmemory4;

Aucun commentaire:

Enregistrer un commentaire