Can you code in C++ without caring about manually allocating memory?
Like C# or java but not shit?
Can you code in C++ without caring about manually allocating memory?
Like C# or java but not shit?
Other urls found in this thread:
en.wikipedia.org
twitter.com
>int num = 1;
Oh look memory has been allocated automatically. What exactly are you referring to?
you know I was refering to avoiding to use pointers, my friend.
Pointers dont allocate memory, they reference it.
you know what I mean when I mention c++ and manually allocating memory, fucktard.
Pointers very are useful. Why would you avoid them?
No. That's not why you use C++. You use C++ when you want that fine grained control.
However, smart pointers and RAII can make it easier to get manual memory management right.
>code in C++ without caring about manually allocating memory
Sure, there are GC libraries for C++ too.
No
>not able to use pointers
Haha I love koding
C++ is not java - bjarne stroustrup
You can use smart pointers and never bother. But you should avoid cyclic graph if you want it to be automagic.
jesus christ dude just remember to delete your object instances when destroying them i mean man it isn't that hard unless you're programming at like the ~enterprise~ level dude
C++ is for brainlets and old timers.
Move on to Rust or Python or C# if you want to code modern programs.
Why stick to manual bullshit when automatic shit is better than 99.999% of the stuff.
Because that shit is too slow and not widely used or supported in the domains I am interested in.
I'm not OP though.
this desu
I don't think you know what you are talking about nearly as much as you think you do. You should go back to your introductory CS class and pay attention.
larp faggot
Nah I'm just a computational scientist. C++ is the most widely used for the sort of numerical shit I do, followed by Fortran.
Python is often used for scripting and shit though.
>I'm a computational scientist
>I don't know how to manage memory
>Nah I'm just a computational scientist
No you aren't
>t. to smart to understand pointers
Why does this board attracts literal retards?
I never said I don't know how to manage memory, like I said, I'm not OP.
>everyone on Sup Forums is a middleschooler
lmao @ ur lief
for real though I'm a 32 year old oldfag doing a post doc in tectonophysics come @ me bruh I've been here for over 10 years lmao
I code in C++ for a microcontroller application, and besides a circular buffer, I don't care about memory allocation.
>doing a post doc
i'm sorry about your retardation.
You don't have to care about memory unless your application is running for a long time.
But it is considered good practice to make a deconstuctor in your class so you call delete if you call new.
You can also use smart pointers and avoid calling delete.
Or you can allocate everything on the stack and not care at all.
>You don't have to care about memory unless your application is running for a long time.
Kill yourself faggot. Might as well write in a garbage collected lang at that point.
Yes. Just use the stack instead of the heap. Everything will be cleaned for you when the function is done.
You can write C++ like C# using .NET
Manual memory managment in in C++ is usually optional unless youre doing really low level stuff or youre messing with C code.
Its also useful for debugging and optimisation.
Basically, if you dont have to mess with memory, dont.
Source: I write C++ on a daily basis.
Not really.
unique_ptr and shared_ptr make it easier because you make it explicit how the memory is intended to be used and who has the right and the responsibility to clean it up, but there's no reference counting or garbage collection.
Say you make a function that you need to run once every day and it exits within a second.
Are you saying that the OS can't manage the resources for him?
Memory leaks doesn't matter in such a case.
But say the application is a driver for a sensor.
It needs to run while the sensor is running, so it falls under "a long time" by any stretch of that sentence.
If he allocates the sensor reading on the heap and never frees it, that driver will crash as he runs out of memory.
Clearly he needs to care in such a situation.
I'm saying you shouldn't be using a manually memory managed language for such a transient and simple thing in the first place.
I use pointers all the time, even in deep embedded projects that don't have malloc.
If you want to program in C/C++ you need to understand pointers, and once you do, properly dealing with malloc/new is pretty straight forward.
> C++
> manual
why do you talk of things you don't understand? modern C++ very rarely calls for manual memory management
Most eggheads are autistic and have very few practical skills. Economics is full of them too
>too much of a brainlet to manage memory yourself
meh not like I have anything better to do with my life ¯\_(ツ)_/¯
If you want "not shit", stay away from C++. I like it for its efficiency and versatility, but it really is a clusterfuck.
And yeah you can avoid using pointers. Just allocate arrays locally or as instance variables.
They have their place, but overusing them in meme constructions where a normal loop and array indices would work just as well, only adds more ways you can fuck up. Before compiler optimization was good, it made for faster code, but now it compiles to the same thing.
Just use the standard containers they are fine for most things especially whatever Java/C# could do and automatically release resources through RAII.
If you mean you want a GC then yes, you can get one in C++ it's just a jewgle search away.
you literally only have to manage the heap yourself,and even that is piss easy in c++ thanks to new/delete and smart pointers.you literally call new just like you do in c# and java you just have to put a delete pointerName; when you are finished.what is so hard about this?im starting to believe that no one on Sup Forums actually knows how to program.