Anonymous
When you return an object from a function, does it return the address of that object?
no. it returns the object. which is copy/move constructed/assigned to at call-site.
Anonymous
there are some situations where the extra function call is elided and the object is directly constructed at the call site as well.
Anonymous
What's call site
place where the function was called from
Anshul
Ok so the object will be returned from function and it'll be copied to the call site object. Right?
Anshul
And will it be shallow or deep copy?
Anonymous
Ok so the object will be returned from function and it'll be copied to the call site object. Right?
In most cases yes. But when Return Value Optimization or NRVO applies then the object is directly constructed at the call site.
Anonymous
And will it be shallow or deep copy?
depends on the object itself and the constructor/assignment operator used.
Amy
Detail program code?
Anonymous
And will it be shallow or deep copy?
This depends on your copy constructors and move constructors.
Anonymous
What's nrvo
Named Return Value Optimization
Anonymous
What's nrvo
https://en.cppreference.com/w/cpp/language/copy_elision
Anshul
'n' denoting the number of strings to sort.. constraint is 1 <= n <= 10^5... when i write this string s[100005]; i get segmentation fault but when i write this int n; cin»n; string s[n].... the code runs successfully. why is it so
Anonymous
'n' denoting the number of strings to sort.. constraint is 1 <= n <= 10^5... when i write this string s[100005]; i get segmentation fault but when i write this int n; cin»n; string s[n].... the code runs successfully. why is it so
The crash happens because you exhausted the stack memory per thread. Btw VLA is not in the C++ standard but instead provided as a compiler extension. So it should not be used in C++ code. It is possible that the compiler optimized out the allocation in the latter case because you are not using the array in anyway. Try taking the address of the array in the latter case and see if it crashes. If it doesnt crash, it is possible that the array is not allocated on the stack but on the heap. The C standard doesnt specify where the array is allocated. It just requires that the array be deallocated at the end of the scope in which it is defined. GCC allocates it on the stack using alloca function on *nix platforms. But it is possible that some other compiler doesnt.
Anonymous
What do you mean by Taking the address?
Taking the address of the array using &<array name>
Anonymous
And also if I do compile time allocation then it is always allocated on stack right? So why will it be allocated on heap.?
The point of VLA is to specify an array size not know at compile time. So how can the allocation be done at compile time?
Anshul
👍
Anonymous
Stack space is NOT as large as ram and is often around 1 to 8 MB on most systems for the application main thread
Yasas
i have a little problem
Yasas
im creating an FPS offline game for IGI fans. should i entirely code my game in c# or should i use unity?
Yasas
or should i use c++?
Yasas
instead of c#?
Anonymous
Unity uses C#
Anonymous
For scripting
Yasas
i mean should i code my game in c++ or make it using unity?
Anonymous
Unity is easier as it does A LOT of stuff for you
klimi
im creating an FPS offline game for IGI fans. should i entirely code my game in c# or should i use unity?
depends on your preference.... short answer would be to use whatever you are comfortable with, long answer would be long... but if you want to discuss it, then i will write it
Yasas
write it then
klimi
then you will have to tell me your motivation behind the project
Anonymous
Such as camera, viewport, 3D objects, animations, coordinates, models, etc are all handled by unity for you
Yasas
then you will have to tell me your motivation behind the project
i wanna buy a better laptop for game developement
klimi
i am afraid i don't understand how it is connected
Yasas
cuz i have 4gb ram, intel core i3 4th gen cpu and gtx 660
Yasas
but my laptop is not powerful enough
klimi
how is that connected to the game you want to create?
klimi
if you want to work for epic games, then you should use their development tools
klimi
if you want to work for epic, then https://www.unrealengine.com/en-US/ would be the way to go...
Yasas
i know
Yasas
epic games created the unreal engine
Yasas
but i need a computer
Yasas
powerful enough to handle it
klimi
then buy a computer and you don't have to decide between c+= and c#
Yasas
thats why im creating this game in the first place
klimi
so it's not about learning to code, but it is about creating a game so you would get money?
klimi
then don't use C++
Yasas
you do not know the pain of being poor
klimi
go for unity
Anonymous
Ontop of that, it handles complex stuff such as scene graphs which handles objects in 3d space relative to both camera and origin Physics loops which are timer driven Shaders, materials, and shadows Lighting And so on
Yasas
i do
what?
klimi
i do know the pain, i was 12 years with i3-380m with gt-310m
klimi
your machine vs my old one is quite powerful
Yasas
i do know the pain, i was 12 years with i3-380m with gt-310m
i had a i3 2nd gen 2gb ram and intel hd 3000 before i got my current one
klimi
yeah, it's enough
Yasas
i earned money by begging in the streets to buy my current one
klimi
i don't think we (as this c/c++ group) can help you in this matter
Yasas
its fine
klimi
+ it's getting quite offtopic... but everyone had to start somewhere....
Anonymous
Basically at the core of ALMOST every game, is some kind of game engine, which handles all or most of the stuff i mentioned Without a game engine of some kind, it is difficult to make a 3D game that is of reasonable quality, if at all
Yasas
so i will stop this discussion here
klimi
if you just want to create game, you can have a look at godot, i have heard it is not as that bad and it is opensource