This is not all Qt question but I would appreciate if you could recommend to me some literature on the following subjects. You will save me the time of sifting through to much books or online documents trying to find answers. Again I tried to be very specific but if I wrote to much I apologize.
I am interested in some good documentation of the parent role in memory management. To read exactly how it is done. I believe it will help me understand the process of memory management in Qt better and help me write better code.
Since I haven't read any good documentation on memory management namely stack and heap I would appreciate recommendation on those topics as well.
I don't know if these terms are C++ bound or Windows bound or both, or are they independent from operation system and programing language.
I have decent experience in ISO C++ and I have recently started to learn Qt, but I am electronics engineer by trade not a programmer so my question might be formulated wrong or just be plain stupid.
To help you understand I will give you an example.
I gathered most of my C++ knowledge from Stanley Lippmans book C++ primer.I read the book some time ago so if I write something wrong it is because I either forgot what the book said or because I understood it wrong in the first place. In the book he writes about two ways of making an object. I will use int in my example for simplicity
int i(2);
int j = 3;
int i(2);
int j = 3;
To copy to clipboard, switch view to plain text mode
In the case of object i the compiler will reserve the memory for object i and fill it with the appropriate value. In the case of j the compiler will reserve the memory for j but will fill its memory space using the default constructor. Then it will create the temporary object of type int, I believe on heap but I am not sure, and then use assignment operator which in turn usually uses copy constructor to copy that temporary object into j. In some cases this might be relevant. Maybe I created the type which uses the copy constructor in its assignment operator. And maybe the copy constructor doesn't create an identical copy because my type has to work like that. It is very important how I create object of that type then.
To further the subject a little. I have decent knowledge of assembler languages, not just the Intel compatible CPUs but many microcontrolers, and it helps me to know how my code is executed machine wise so to speak. I know that some of you might frown on this but I believe this is good stuff to know.
To try to explain why. I started Microsoft course on C# today. My company paid for some of us to go on this course. We had to do an exercise which consisted of making a simple form making two classes and using some getter and setter methods manipulate those classes. The constructor for bankAccount class was
public BankAccount(string userName, int userBalance)
{
name = userName;
balance = userBalance;
}
public BankAccount(string userName, int userBalance)
{
name = userName;
balance = userBalance;
}
To copy to clipboard, switch view to plain text mode
The default constructor was
public BankAccount() : this("unknown", 0)
{
}
public BankAccount() : this("unknown", 0)
{
}
To copy to clipboard, switch view to plain text mode
This is C# code don't be confused. When I asked our instructor can I write
public BankAccount(string userName, int userBalance) : name(userName), balance(userBalance)
{
}
public BankAccount(string userName, int userBalance) : name(userName), balance(userBalance)
{
}
To copy to clipboard, switch view to plain text mode
because every professor on college and mister Lippman in his book made the remark that constructor from the last example initialize the members of the class, while the one from the first example initialize them using the default constructor and then uses the assignment operator and in most cases copy constructor to copy the values passed to the objects constructor.
The instructor either didn't know what I am talking about or refused to explain and just said you can't write the constructor like that you have to you the first one.
I went on this course not because I have much interest in C# but because it was free. If my company is willing to pay for me to learn something that might be useful for me I am not going to say no. But C/C++ is, in my humble opinion, still by far the best programing language I had the chance to program in. So I think that learning about stack, heap and Qt parenting methods for memory management will help me become better. So if you could recommend me literature on these topics I would appreciate it very much.
Thank you in advance. Sorry if my post was to long and if my english is not very good.
Bookmarks