[ 3 / biz / cgl / ck / diy / fa / g / ic / jp / lit / sci / tg / vr / vt ] [ index / top / reports / report a bug ] [ 4plebs / archived.moe / rbt ]

Due to resource constraints, /g/ and /tg/ will no longer be archived or available. Other archivers continue to archive these boards.Become a Patron!

/g/ - Technology

View post   

[ Toggle deleted replies ]
File: 125 KB, 1024x800, 1473763802401.jpg [View same] [iqdb] [saucenao] [google] [report]
63995783 No.63995783 [Reply] [Original] [archived.moe] [rbt]

Can you code in C++ without caring about manually allocating memory?

Like C# or java but not shit?

>> No.63995823

>int num = 1;

Oh look memory has been allocated automatically. What exactly are you referring to?

>> No.63995854

you know I was refering to avoiding to use pointers, my friend.

>> No.63995857

Pointers dont allocate memory, they reference it.

>> No.63995917

you know what I mean when I mention c++ and manually allocating memory, fucktard.

>> No.63995929

Pointers very are useful. Why would you avoid them?

>> No.63995931

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.

>> No.63996080

>code in C++ without caring about manually allocating memory
Sure, there are GC libraries for C++ too.

>> No.63996253


>> No.63997184

>not able to use pointers
Haha I love koding

>> No.63997238


>> No.63997287

C++ is not java - bjarne stroustrup

>> No.63997629

You can use smart pointers and never bother. But you should avoid cyclic graph if you want it to be automagic.

>> No.63997652
File: 2.64 MB, 320x240, 1383967436971.gif [View same] [iqdb] [saucenao] [google] [report]

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

>> No.63997705

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.

>> No.63997716

Because that shit is too slow and not widely used or supported in the domains I am interested in.

I'm not OP though.

>> No.63997794

this desu

>> No.63997800

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.

>> No.63997827

larp faggot

>> No.63997852

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.

>> No.63997866

>I'm a computational scientist
>I don't know how to manage memory

>> No.63997871

>Nah I'm just a computational scientist
No you aren't

>> No.63997889
File: 279 KB, 898x790, f93.png [View same] [iqdb] [saucenao] [google] [report]

>t. to smart to understand pointers
Why does this board attracts literal retards?

>> No.63997913

I never said I don't know how to manage memory, like I said, I'm not OP.

>everyone on /g/ 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

>> No.63998178

I code in C++ for a microcontroller application, and besides a circular buffer, I don't care about memory allocation.

>> No.63998192

>doing a post doc
i'm sorry about your retardation.

>> No.63998211

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.

>> No.63998226

>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.

>> No.63998448

Yes. Just use the stack instead of the heap. Everything will be cleaned for you when the function is done.

>> No.63998883

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.

>> No.63999058

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.

>> No.63999113

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.

>> No.63999145

I'm saying you shouldn't be using a manually memory managed language for such a transient and simple thing in the first place.

>> No.63999447


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.

>> No.63999580

> C++
> manual

why do you talk of things you don't understand? modern C++ very rarely calls for manual memory management

>> No.63999642

Most eggheads are autistic and have very few practical skills. Economics is full of them too

>> No.63999658
File: 38 KB, 645x729, 1506099476321.png [View same] [iqdb] [saucenao] [google] [report]

>too much of a brainlet to manage memory yourself

>> No.63999686

meh not like I have anything better to do with my life ¯\_(ツ)_/¯

>> No.63999691

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.

>> No.64000383

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.

>> No.64001269
File: 81 KB, 1082x720, 1513959930460.jpg [View same] [iqdb] [saucenao] [google] [report]

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 /g/ actually knows how to program.

Name (leave empty)
Comment (leave empty)
Password [?]Password used for file deletion.