|
vidya556 wrote: i had attended an interview so i was asked this but i couldn't understand
Really? You've applied for a job as a C++ programmer (presumably) and you don't know about memory management?
All of those questions are pretty basic, and even if you didn't go into a lot of detail, you should have been able to show a basic understanding of the subject.
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
I am from a mechanical background and fresher so had told him whtever i had know abt the new and delte but he was not satisfied wid the answer.
So is the reason i am asking u guys wid lot of experience to give me the perfect answer for all the above question.
If u find it pretty simple y don't u share the knowledge.
|
|
|
|
|
If you're a fresher, then I'd guess he wanted to judge your level of knowledge for what he'll be teaching you in class. I wouldn't expect someone starting out in progrmming to know much about memory managers, or anything else really.
Anyway, the subject s quite complex, and would take several pages to explain all the details, particularly to the level asked for in your original post. There's really no way anyone can give you the information you need in a single short answer on this board. Your best approach, if you really want to learn this stuff, is to use Google, and read books on the subject.
Alternatively you could ask your tutor / lecturer if he expects you to know this, or if it's part of what he'll be teaching.
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
There are rules[^] to post a query on this forum. Your query does not comply with those, so don't be surprised if you are not being helped.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
|
i am planning to write a function with less than 20 lines
so i ma doubted whether to use inline or macro?
which is better?
|
|
|
|
|
How would declaring a function inline decrease the number of lines of code?
Out of curiosity, what's a "Be programmer"?
|
|
|
|
|
He progressed from "A programmer"?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
And soon he will only "see programmer"
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Michael Schubert wrote: Out of curiosity, what's a "Be programmer"?
Whether to be or not to be, that's his question.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: Michael Schubert wrote:
Out of curiosity, what's a "Be programmer"?
Whether to be or not to be, that's his question.
ToBe OR NOT ToBe == -1
Sorry, couldn't resist....
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Be programmer wrote: inline or macro
There are very, very, very, very few reasons to ever consider using a macro rather than an inline function. In fact, your question is a subset of the second item in Scott Meyer's Effective C++ (one of the C++ textbooks you really want to read):
Item 2: Prefer consts, enums, and inlines to #defines
The reasons?
- Macros live outside the type system
- Macros pollute all namespaces
- There can be unexpected outcomes from macros. Consider the following macro function and it's use:
#define CALL_WITH_MAX(a, b) f((a) > (b) ? (a) : (b))
CALL_WITH_MAX(++a, b);
CALL_WITH_MAX(++a, b+10);
Can you predict that reliably? Nope, thought not.
So, to paraphrase...just don't ever use a macro instead of an inline function.
Don't try to micro-optimise before you know what the slow things are...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
In addition to what Stuart said, an inline function probably won't actually "inline" in the compiler if it's 20 lines long. If it's only a few lines, then it might. And I wouldn't really consider 20 lines to be that "small." Generally you only want to inline 1-liners or maybe a few more lines than that, but the compiler will ultimately decide what it lets you inline even if you specifically set the function to be an "inline" function.
KR
|
|
|
|
|
Regardless of the usefulness, you can force most compilers to inline (__forceinline) , no matter how much code is involved.
|
|
|
|
|
Hi Mike,
I always thought even with the __forceinline keyword, the compiler had an option to ignore it and not inline the function (if it feels so). So, is that wrong and the keyword causes the compiler to forcefully make the function inline?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
I had mixed results when I played around with this. The VC6 compiler does ignore __forceinline when a function is beyond a certain complexity/size, especially when there is a call to another function within.
The Intel C++ compiler (at least newer versions) has a bunch of switches to control inlining and lets you inline almost every function. When you try that with a large function, the final .obj (and the resulting .exe) file(s) will be huge.
After a lot of testing I realised that it's usually best to let the compiler decide (/Ob2). The Intel compiler is especially good in this regard.
|
|
|
|
|
Michael Schubert wrote: I had mixed results when I played around with this. The VC6 compiler does ignore __forceinline when a function is beyond a certain complexity/size, especially when there is a call to another function within.
Exactly! I've struggled with this a few years back (VC6 compiler) which ignored the keyword and made it a normal function, realising that the function is a little more complex than what should it be to qualify as an inline one.
I wanted it to be inline because I kept some of the code for application validation and secure updates (based on the version purchased) in that. The function was being called from several places in the source and I didn't want it to be pointing to one function call (trying to make a cracker's job a little tough). So, I realised this is an arrogant display of - "I know it better than you, so you cannot force me" attitude by the MS compiler. They might as well remove this keyword; I don't find it to behave any different the __inline keyword.
Good to know the intel compiler just does what we ask it to do. But, after all, MS knows what's best for us, better than we do.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: I always thought even with the __forceinline keyword, the compiler had an option to ignore it and not inline the function (if it feels so).
You're right. Anyway, you may then consider __force_tha_fu@kin_function_inline_bastard directive, that usually do the job.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'd love to have the directive though.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
|
I second that.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi every one,
we for an STL container we can use both iterator or indexing method to access the
container data, but still y iterators are preferred i mean what is advantage of
using iterator over legecy indexing...
please answer me...
if u feel silly still iam the begineer and even tried to google but
didnt found the destiny..
|
|
|
|
|
|
Iterators are a more generic and flexible concept than indices. They allow you to access the item they reference without having to refer to the parent container. Indices can't do that - they need to be explicitly used with the container they index.
Things like polymorphic algorithms (like in the STL header algorithm) would be tricky to implement with indices...
The Wikipedia page on iterators[^] has quite a good explanation.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I searched over and found that gotoxy() is defined in conio.h!!!!!!
Is it write.
I want to use gotoxy() to print the text at some other location than the origin in the following program. This program is basically a informal animation of the text entered. The code is given below.
#include<stdio.h>
#include<windows.h>
#include<conio.h>
main()
{ static char ch[100], rev[100];
int n=0,c=0,d=0,i=0,h=0,k=0,r=0;
for(n=0;n<100;n++)
{ch[n]=getche();
if(ch[n]=='\r')
break;}
system("cls");
gotoxy(20,18);
while(1)
{for(h=1,k=n;h<100,k>n/2;h++,k--)
{if(h>n)
break;
for(c=0;c<h;c++)
printf("%c",ch[c]);
for(d=n,r=0;d>k-1,r<100;d--,r++)
{
rev[r]=ch[d-1];}
for(i=h-1;i>=0;i--)
printf("%c",rev[i]);
Sleep(1000);
system("cls");}}}
|
|
|
|