new-operator

Understanding template classes in c++ - problem with new-operator

Dear all, I've been stuck with this problem now for a few days and my searches were not successful. What I am trying to do: I want a template reader class (VariableReader) to handle different types of variables (usually unsigned int and pointers to vector). I started with #ifndef READER_H_ #define READER_H_ #include <string> namespa...

Runtime allocation of multidimensional array

So far I thought that the following syntax was invalid, int B[ydim][xdim]; But today I tried and it worked! I ran it many times to make sure it did not work by chance, even valgrind didn't report any segfault or memory leak!! I am very surprised. Is it a new feature introduced in g++? I always have used 1D arrays to store matrices by ...

Replacing libstdc++.dylib (4.0) global new and delete operators on OSX

I'm trying hard to replace the global new and delete operators with XCode 3.2, GCC 4.2, libstdc++ 4.0, dynamic version. I took the protypes directly from the header "new" and implemented them. They are pasted below. The project is a .plugin so a dynamic lib. This plug-in MUST delegate allocation to the main application's own alloc/fre...

Silverlight : Create Generic Control from backgroundWorkder Thread

Hi, I'm in trouble when using the background worker to create my object model. As I understand why, I'm unable to find a workaround. Here is the pseudo logic : Call Webservice async When received, open a background worker, and load data into controls in the background in the Load method, search for an existing object and if not foun...

Does new[] call default constructor in C++?

When I use new[] to create an array of my classes: int count = 10; A *arr = new A[count]; I see that it calls a default constructor of A count times. As a result arr has count initialized objects of type A. But if I use the same thing to construct an int array: int *arr2 = new int[count]; it is not initialized. All values are somet...

Overloading operator new [] in C++ fails with Visual C++

Hi, I have code that overloads operator new. The code below works fine under Linux (gcc4x) but not Windows ( Visual C++ 2008 Express Edition) The code under Visual Studio 2008 Express Edition reports error C2660: operator new[] : function does not take 1 arguments Thank you very much! class dummy{}; void* operator new[] (size_t si...

Convention in java - "new" oustide of constructor / function ?

Hello. Simple question. A friend of mind wrote code similar to this one (which is just to explain you my question, it's not useful at all....) class Example{ private int[] tab = new int[10]; public Example() { for(int i = 0 ; i < 10 ; i++) tab[i] = (int)(Math.random()*100); for(int i = 0 ; i < 10 ; i...

C++ overloaded new[] query : What size does it take as parameter ?

I have overloadded operator new[] like this void * human::operator new[] (unsigned long int count){ cout << " calling new for array with size = " << count << endl ; void * temp = malloc(count) ; return temp ; } and now calling human * h = new human[14] ; say sizeof(human) = 16 , but count it prints is 232 wh...

Shouldn't this code crash

int *p; while(true) { p = new int; } Due to running out of memory space, shouldn't this code crash. I have tried printing out the value of p, that is the address of memory located for p, and it seems to increase yet there is no crashing. Why is this so? ...