Why do both delete and delete[] exist?

Why do both delete and delete[] exist?

Attached: BStroustrup_MAIN-720x510.jpg (720x510, 44.28K)

i dunno

this is now a bjarne thread

Attached: 1656079018475.png (432x324, 219.54K)

good morning sir

Attached: 1631594310282.png (800x1300, 1.11M)

You actually learn better with constant interruption

ROBOT

I am currently learning C++, having learned C before that, I must say that I enjoy it very much. Though C still has a special place in my heart.

Attached: bjarne.jpg (121x175, 4.75K)

Good morning Sirs!

This is a blatant design mistake with no justification whatsoever, especially considering that it's a feature that C++ itself introduced and not something it inherited from C.

The memory returmed by ”new" already stores the amount of memory used (so that "delete" can deallocate the correct amount). This information could, and should be used all the same whether you're deleting an array of objects or a single object. There is no reason whatsoever for having two separate deletion operators, it's just inviting subtle errors for no actual gain in expressiveness.

In C, at least you have a single function, free, which will always do the right thing no matter how the memory was allocated, be it using malloc, calloc, realloc, etc. I'm aware that you technically have these functions in C++ too, but it's considered an evil bad practice so nobody uses them.

delete[] is for dynamically allocated arrays and using regular delete on one is undefined I think

>I'm aware that you technically have these functions in C++ too, but it's considered an evil bad practice so nobody uses them.
These days manually using new and delete instead of smart pointers is considered an evil bad practice

c++ is basically turning into a garbage collected language

Bjased Stroustrup

Yes, but without the benefits of real GC.

what types of projects does one work on in c++? are companies even recruiting for it? I never see job posts for it

good morning sir!

Attached: 1651356267811.jpg (1240x744, 80.8K)

Attached: bjarnefrog.jpg (640x640, 295.65K)

>Occult programmer
Dear god, we use to bully fags out of stupid shit like this on the AoE and MU online days and they turned out just fine.

Attached: 1659323241350.jpg (706x960, 53.44K)

walter becker

Game development, compilers, high performance computing, digital signal processing, etc.

Daily reminder that your IQ is priced in by 23

Attached: T0T0RY.png (600x600, 518.26K)

Because int is a different type than int[]

It's not really garbage collection, although there are features in the C++ standard that would allow for it (no one has bothered implementing them). RAII, aside from being the worst initialism ever invented, is basically just compiler generated code. Actual garbage collection generally requires a separate runtime that runs periodically to perform the actual garbage collection. This has advantages and disadvantages. Namely, you won't need to worry about the garbage collector randomly causing you to drop frames or miss timing on your application. Downside, you don't get guaranteed memory safety and miss out on some optimizations garbage collectors do for massive collections of reference counted allocations. Specially shared pointers in C++ are slow because they require atomic operations to handle.