Questions from a "dummy" - page 106

 
uncleVic:
Task... Please attach a signal module (I don't have one). Let's have a look.
Files:
 
openlive:

It's even weirder. The effect is not playing out for me.
 
uncleVic:

Even weirder. I don't get the effect.

effect only during initialisation, in the tester everything is normal

OK, I don't need it, I don't really need it.

 

The Zigzag indicator reads values that no longer exist (they must have been there before redrawing). Can this be avoided?

If the values are in the buffer, why isn't it drawing again...

 

Good afternoon, please explain the following:

class Cbase
{
public:
        virtual ~Cbase(){};
        int k;
};

class Cchild:public Cbase
{
public:
        ~Cchild(){};
        double *p;
        int f;
};

I have two classes, I believe that the next generation instance (base - child - child2 - ...), takes more and more space in memory. To operator New, we say exactly how much memory to allocate, passing the class in parameters. But in the delete operator, we do not say exactly how much memory to allocate. Proceeding from this reasoning, it is not quite clear what will happen in the next situation:

void fn()
{
   Cbase *pClass;
   pClass = new Cchild;
   delete pClass;
   return;
}

I.e. I mean we declared *pClass as a pointer to Cbase (a small class compared to Cchild), but it actually points to Cchild. Hence the question, how willdelete() behave? Will it free the number of bytes equal to the size of Cbase (then memory will be clogged), or will deletion occur correctly?

P.S: well, one more question on the subject: is there any label in allocated memory area (new), with which we can understand size of this area (something like char is stored with zero terminator at the end)? Or in other words, can a piece of code which doesn't know anything about the sizes of classes I've declared correctly free memory?

 

220Volt:

The question is, how willdelete() behave? Will it free number of bytes equal to Cbase size (then memory will be clogged), or will delete occur correctly?

Of course, it will free memory correctly.

P.S: well, one more question on the subject: is there any label in allocated memory area (new), with which you can understand the size of this area (something like how char is stored with zero terminator at the end)? Or in other words, can a code fragment that knows nothing about sizes of classes I've declared correctly free memory?

sizeof ?
 
sergeev:

of course it will delete correctly. you can spread the brickpoints over the destructors

That's about where this question is coming from. Did about as described (destructor was not virtual), and destructors below pointer class were not called.
 
sergeev:
sizeof ?
I think sizeof works at compile time, but I'm talking about freeing memory from another process for example. If this is possible, then I think the delete function is understandable.
Документация по MQL5: Основы языка / Операторы / Оператор уничтожения объекта delete
Документация по MQL5: Основы языка / Операторы / Оператор уничтожения объекта delete
  • www.mql5.com
Основы языка / Операторы / Оператор уничтожения объекта delete - Документация по MQL5
 
Destructors in MQL5 are always virtual. Everything is deleted correctly, try to put Print(__FUNCSIG__); in destructors.

class CFoo
  {
public:
   ~CFoo() { Print(__FUNCSIG__); }
  };

class CBar : public CFoo
  {
public:
   ~CBar() { Print(__FUNCSIG__); }
  };

void OnStart()
  {
   CFoo *f=new CBar();
   
   delete f;   
  }
 
The question is not even more about what we've set in the class functions via new, but about the class data of its "native" members. After all, they are not empty spaces either.
Reason: