is C++ worth it ?

8

88888 Dihedral

Melzzzzzæ–¼ 2012å¹´8月20日星期一UTC+8上åˆ5時19分26秒寫é“:
That would be possible only if memory cannot be exhausted ;)



Melzzzzzæ–¼ 2012å¹´8月20日星期一UTC+8上åˆ5時19分26秒寫é“:
That would be possible only if memory cannot be exhausted ;)

OK, lets talk about programming in C++ with the container librariy.

Well, the results of the Fibnaci series, Fib(n) can not be stored
in 32 or 64 bits except those trivial cases for novices.

But if I need to genenrate Fib(2000) in C++, then the long integer
part is not standardized in C++ aftr so manny years.
 
N

Noah Roberts

low level programming? Interfacing to hardware?

Depends. If you have a static, known size that cannot change and you want to use automatic variables then the C data types are a good response. As soon as there is variant size or you're allocating on the heap though it is better to have a class of some sort with RAII semantics. In most cases, with any optimizations turned on at all, std::vector<char> is just as fast aschar[].
 
Ö

Öö Tiib

On Sun, 19 Aug 2012 13:47:52 -0700 (PDT)







That would be possible only if memory cannot be exhausted ;)

I explained *how* *that* *is* *mitigated* in the part that you snipped. Read again.
 
Ö

Öö Tiib

low level programming? Interfacing to hardware?

Depends. If you have a static, known size that cannot change and you want to use automatic variables then the C data types are a good response. Assoon as there is variant size or you're allocating on the heap though it is better to have a class of some sort with RAII semantics. In most cases, with any optimizations turned on at all, std::vector<char> is just as fast as char[].

There is std::array<T,N> now and has been boost::array<T,N> for long time for static sized arrays. AFAIK those assert on out of limits in []() and throw on out of limits in at() like with vectors. When NDEBUG is defined then generated instructions for usage of a[n] are exactly same as with raw array..
 
J

Jorgen Grahn

Use the right tool for the job. For certain use cases, although
considerably less as time goes on, you need the low level features of
C, C++, or Ada. JITs are getting so good, though, that for typical
32-bit programming, using C++ amounts to a micro-optimization.

What if I don't use C++ because I need extreme performance and
low-level things, but primarily because I believe it's a better
high-level language for expressing my design?

The low-level things are not the the main benefits of C++. If they
were, I'd use Python everywhere, since it has been fast enough for me
in 99% of all cases.

/Jorgen
 
R

Rui Maciel

Leigh said:
You are seriously saying that all Internet servers must be implemented
using GC due to the unsafeness of C++ pointers and viruses? What utter
nonsense.

I suspect he meant that GC is used by some programmers as an excuse to cover
up their failure in putting in place a working memory management policy.


Rui Maciel
 
F

fungus

When I changed this:

public static void sum(int[] data) {

if(data.length == 0) return;

for( int i = 1; i != data.length; ++i)

data += data[i-1];

}



to this:

static void sum(std::vector<int>& data) {

if(data.empty()) return;

for( unsigned i = 0; i < data.size() - 1; ++i)

data[i+1] += data;

}


You didn't think that having the same result
was important?
 
M

Melzzzzz

When I changed this:

public static void sum(int[] data) {

if(data.length == 0) return;

for( int i = 1; i != data.length; ++i)

data += data[i-1];

}



to this:

static void sum(std::vector<int>& data) {

if(data.empty()) return;

for( unsigned i = 0; i < data.size() - 1; ++i)

data[i+1] += data;

}


You didn't think that having the same result
was important?


I think that's equivalent...
 
J

James Kanze

Aha. You mean deallocating block of memory while still being used.
I think that's a bug in software. Does not happens usually...

It's clearly an error in the software. In practice, it happens
a lot. There are well known techniques to exploit it. (In
practice, they're not used that much, because the techniques to
exploit buffer overflow are easier, and that's another frequent
error.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top