C++ vs Java "new" (no flame war please!)



Do not take anything about this, it is not a flame or troll, while I'm not
new to Java I favor C++. However, I may need to use it in a contract
position, and am concerned that the restrictions it places on application
code.

Take, for instance, this C++ construct:

class foo
{
char *m_name;
....
void * operator new(size_t size, char *string);
}


void *foo::new(size_t size, char *string)
{
size_t cbstr = strlen(string)+1;
size_t cb = cbstr + size;
foo * t = (foo *) malloc(cb);
char * name = (char *) &t[1];
strcpy(name, string);
t->m_name = name;
}

The above example is a methodology that can be used to reduce the CPU and
memory overhead of malloc. You my argue that this is not a valid concern,
but if you have 10 or 100 million objects, the malloc block overhead,
alone, make this worth while. Hint: This is actually a simplification, some
times malloc is not used at all, and a big array is pre-alocated and work
through it with each new.


Is there a way to create 10 to 100 million objects in Java with a reasonable
system configuration?



.



Relevant Pages

  • Re: OO compilers and efficiency
    ... >>> performance is due to Java implementations failing to optimise common OO ... > single good language designer. ... >> situations where a GC would outperform manual allocation though. ... >> Yes, that's true, but malloc and free are generally very efficient. ...
    (comp.programming)
  • Re: Java outperforms C++?
    ... It's true that managed versus unmanaged code does not mean respectively slow ... Ever thought of the things "malloc" does before returning ... Ofcourse, if you are an experienced coder, you have created memory pool ... they compare recursive C++ functions with iterative Java calls? ...
    (microsoft.public.vc.language)
  • Re: IBM article on Java performance
    ... mallocand memory allocation in Java doesn't even resemble each ... other so I can't really understand how optimizations possible for one ... of malloc() or free. ... in Java you have no such restriction. ...
    (comp.lang.java.advocacy)
  • Re: Good books for a complete beginner!
    ... And actually I believe Monique is a boys' name. ... Java and javascript are different. ... finally saw a malloc() for the first time instead of a new. ...
    (comp.lang.java.help)