On Monday, 14 September 2015 at 20:54:55 UTC, Jonathan M Davis
wrote:
On Monday, September 14, 2015 01:12:02 Ola Fosheim Grostad via
Digitalmars-d-learn wrote:
On Monday, 14 September 2015 at 00:41:28 UTC, Jonathan M Davis
wrote:
> Regardless, idiomatic D involves a lot more stack
> allocations than you often get even in C++, so GC usage
> tends to be low in
Really? I use VLAs in my C++ (a C extension) and use very few
mallocs after init. In C++ even exceptions can be put outside
the heap. Just avoid STL after init and you're good.
From what I've seen of C++ and understand of typical use cases
from other
folks, that's not at all typical of C++ usage (though there's
enough people using C++ across a wide enough spectrum of
environments and situations that there's obviously going to be
quite a wide spread of what folks do with it). A lot of C++
folks use classes heavily, frequently allocating them on the
heap.
Dude, my c++ programs are all static ringbuffers and stack
allocations. :)
It varies a lot. Some c++ programmers turn off everything runtime
related and use it as a better c.
When targetting mobile you have to be careful about wasting
memory...
types of heap allocations in your typical C++ program - e.g.
make_shared has become the recommended way to allocate memory
in most cases
I use unique_ptr with custom deallocator (custom freelist), so it
can be done outside the heap. :)
And while folks who are trying to get the bare metal
performance that some stuff like games require, most folks are
going to use the STL quite a bit.
I use std::array. And my own array view type to reference it.
Array_view us coming to c++17 I think. Kinda like D slices.
STL/string/iostream is for me primarily useful for init and
testing...
such as Qt. It's the folks who are in embedded environments or
who have much more restrictive performance requirements who are
more likely to avoid the STL or do stuff like avoid heap
allocations after the program has been initialized.
Mobile audio/graphics...
So, you _can_ have low heap allocation in a C++ program, and
many people do, but from what I've seen, that really isn't the
norm across the C++ community in general.
I dont think there is a C++ community ;-) I think c++ programmers
are quite different based on what they do and when they started
using it. I only use it where performance/latency matters. C++ is
too annoying (time consuming) for full blown apps IMHO.
Classes are easy to stack allocate though, no need to heap
allocate most of the time. Lambdas in c++ are often just stack
allocated objects, so not so different from D's "ranges"
(iterators) anyhow. I don't see my own programs suffer from
c++isms anyway...