0

Would it be a good idea for me to learn something what dynamic variables actually mean and how they help to make my windows Vista ?

I have heard that

int* g=new int[50];

is supposed to dynamically allocate memory for an array of 50 integers. And g is called a dynamic variable too. If so, what are dynamic variables in my windows ? I think this is more of a concept than of some computable objects to define. And I am in the middle of nowhere between both.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Please google for `C tutorial` first. You will not understand the answer without basic knowledge about C language. – Andrejs Cainikovs Aug 16 '11 at 16:44
  • 3
    First part is correct, g is pointing to dynamically allocated memory. But g is not a dynamic variable, there is no such thing in C++. I have no idea what you mean by 'variables in my windows'. – john Aug 16 '11 at 16:44
  • 1
    It would benefit you to get [a good introductory C++ book](http://stackoverflow.com/questions/388242/the-definitive-c++-book-guide-and-list). – James McNellis Aug 16 '11 at 16:47
  • 1
    @Andrejs: C doesn't even have `new`, so... no. And tutorials should _always_ be eschewed in favour of a good, recommended book. – Lightness Races in Orbit Aug 16 '11 at 16:51
  • 1
    "and how they help to make my windows Vista " eh? – Lightness Races in Orbit Aug 16 '11 at 16:51
  • @Tomalak Geret'kal: Correct. But I don't see any reason going directly for C++, if there is no C understanding. This will damage a healthy mind. – Andrejs Cainikovs Aug 16 '11 at 16:59
  • 3
    @Andrejs: I could not disagree more. C++ is a distinct language to C, with its own conventions and idioms. Any good C++ book will teach you all you need to know: there is no reason to poison your mind with conventions and idioms from C -- a _different_ language -- just to pick up the common subset of concepts. And there's absolutely no reason to encourage that in programming newcomers, either. The answer to "should I learn C before C++?" is a firm **no**! – Lightness Races in Orbit Aug 16 '11 at 17:03
  • 1
    @Tomalak Geret'kal: Sure, it's a different language. But to understand what is pointers, memory allocation, and other fundamental things - IMHO C is far more suited for newcomers than C++. It's just.. simpler to understand, even if one likes to dig into details. Anyway, it's a separate topic, and I'm not really a C++ fan. ;) – Andrejs Cainikovs Aug 16 '11 at 17:13
  • Thank you everyone for your instructions. @Tomalak, I restate my question in your reply's comment section. – Real Bite of Life Aug 16 '11 at 17:16
  • @Andrejs: Simpler to understand? Learning pointers and [basic concepts of] memory allocation has roughly the same complexity in either language, but if you're learning C++ then a C++ book gives you the advantage of teaching you the _correct_ syntax, conventions and idioms, rather than those of some other language that you're _not_ using. – Lightness Races in Orbit Aug 16 '11 at 17:17
  • @RealBite: Please clarify questions by editing the question text, not by hiding the information in some comment somewhere! – Lightness Races in Orbit Aug 16 '11 at 17:18
  • I'm going to write a song entitled "variables in my windows" – Lightness Races in Orbit Aug 16 '11 at 17:18
  • @Tomalak Geret'kal: No, it's not. `malloc` is not the same as `new`. To understand what `new` operator is doing you need to understand what OOP is, while `malloc` is just.. Memory ALLOCation ;) – Andrejs Cainikovs Aug 16 '11 at 17:19
  • @Andrejs: You skipped over "[basic concepts of]" when you read my comment. And, no, you don't need to understand OOP to understand `new` at all; what nonsense! – Lightness Races in Orbit Aug 16 '11 at 17:21
  • @Tomalak Geret'kal: Sorry, you probably have updated your comment. What about `new` on object? But anyway: http://www.docme.ru/doc/20742/the-dark-side-of-c%2b%2b#.ThXRw5ezc7Q.facebook – Andrejs Cainikovs Aug 16 '11 at 17:24
  • 1
    @Andrejs: `int` is an object. `new int`. No OOP lessons required. – Lightness Races in Orbit Aug 16 '11 at 17:33
  • @Andrejs: The presentation makes some good points. But you can't just throw up a ridiculously retarded piece of C++ then use it as proof that C++ is "hard to read", and slide 15 is just complete gibberish. Slide 16 [completely lies about exceptions in constructors](http://codepad.org/Qi4ZAZAx), and constructors are not `void` at all. I could go on. – Lightness Races in Orbit Aug 16 '11 at 17:37
  • @Tomalak Geret'kal: I think I could argue about this topic for years. But.. thanks for a good talk. ;) – Andrejs Cainikovs Aug 16 '11 at 17:39
  • @Andrejs: And you! I think I will write a blog post debunking this presentation; continuing to read through it, I think that it is actually dangerous. – Lightness Races in Orbit Aug 16 '11 at 17:40

1 Answers1

2

You should definitely read a good book, but I'll give you some brief answers here anyway.

Would it be a good idea for me to learn something what dynamic variables actually mean?

Yes.

I have heard that

int* g=new int[50];

is supposed to dynamically allocate memory for an array of 50 integers.

That's right.

And g is called a dynamic variable too.

There may be people who use this terminology, but I haven't heard it and I wouldn't adopt it.

g itself is not dynamic at all. It's a pointer, with automatic storage duration ("on the stack" in colloquial language). It has no particularly magic properties.

The "dynamic object" here is the array of fifty integers. This object has no name, and you can only access it through the pointer g (or through another pointer with the same value as g).

If so, what are dynamic variables in my windows ? I think this is more of a concept than of some computable objects to define. And I am in the middle of nowhere between both.

And I don't understand this part of the question at all.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Thank you Tomalak, _This object has no name, and you can only access it through the pointer g (or through another pointer with the same value as g)._ I would like to understand what does the _*name*_ you mention mean. Is a dynamic object supposed to include also a name ? I would like to apply the definition dynamic variables or objects (as you said) into something I see more common, that is why I would like to know in my Windows (Vista), what are dynamically created ? – Real Bite of Life Aug 16 '11 at 17:14
  • Like the pointer object has a name `g`, which comes from the name of a variable that represents it. I suppose actually the dynamically-allocated object _does_ have a name, which comes from the dereference expression `*g`. – Lightness Races in Orbit Aug 16 '11 at 17:16
  • If you're asking about the details of the Windows Vista codebase, including which variables they dynamically allocate, then that is heavily specific, heavily _proprietary_, and completely useless to know. What are you _really_ trying to find out here? – Lightness Races in Orbit Aug 16 '11 at 17:16
  • Thank you, I would like to know some examples of dynamic objects in real life applications, and I choose Windows as the most common one people all play with. – Real Bite of Life Aug 16 '11 at 17:38
  • @Real: You're better off taking a far smaller project to case study. Windows is _huge_. – Lightness Races in Orbit Aug 16 '11 at 17:49
  • @Real Bite of Life: Yes Windows includes thousands, even millions, of dynamically allocated objects. Almost every other application would be the same as well. – john Aug 16 '11 at 19:54