Different behaviour of new and malloc
Namespace
rswhite4 at googlemail.com
Sat Apr 13 14:22:14 PDT 2013
I have a problem and maybe one you can explain, why this failure
happen.
Initial situation:
I have a opengl texture and I want to copy the pixel. I store the
original pixel in an ubyte pointer and allocate new pixel memory
with:
ubyte[] newPixel = new ubyte[this.width * this.height *
this.depth];
and copy the pixel with
newPixel[] = *orgPixel;
or
memcpy(&newPixel[0], orgPixel, this.width * this.height *
this.deph);
Both compiles without errors or warnings.
But if I want to store the newPixel in a new Texture, I see only
black, no matter what method I use.
But if I change my allocation to
ubyte* newPixel = cast(ubyte*) GC.malloc(this.width * this.height
* this.deph * ubyte.sizeof);
and copy then with
memcpy(&newPixel[0], orgPixel, this.width * this.height *
this.deph);
it works fine and I see the copied texture.
My question is: why? What is the difference between both ways of
allocations?
More information about the Digitalmars-d-learn
mailing list