Login  Register

Re: CommandQueue/Buffer change request

Posted by Michael Bien on Nov 22, 2011; 5:40pm
URL: https://forum.jogamp.org/CommandQueue-Buffer-change-request-tp3525736p3528438.html

On 11/22/2011 06:10 PM, Matthias [via jogamp] wrote:
Hello,
...if i saw it correctly
writeBuffer.getNIOSize() just returns writeBuffer.capacity();
...using limit and mark was just an idea how the Java-Api could be used to avoid an additional method.

But an additional method would be great too, thanks a lot for the fast response.

regards

Matthias


you are right. However i have to admit that i am no big fan of using the position/limit storage in buffers. This leads to bad code (potential bugs) like this:

int pos = buffer.position();
int limit = buffer.limit();

buffer.position(myPos).limit(myLimit); // breaks code if buffer is used in multiple threads
api.doSomething(buffer);
buffer.position(pos).limit(limit)


to do this properly you would have to:
Buffer mybuffer = buffer.duplicate().position(myPos).limit(myLimit);
api.doSomething(buffer);
which basically nobody does since everyone believes that duplicate copies the buffer...



having the two params in the method only looks more verbose if you read the doc but in fact it is:
api.doSomething(buffer, pos, lenght);
or
api.doSomething(buffer, buffer.position(), buffer.limit()-buffer.position());


adding mutable state to nio wasn't a good idea back than IMO.

btw, here is the changeset:
https://github.com/mbien/jocl/commit/023747ae952bbc79c02e2a38d581ab6dd85e72e0

best regards and thanks for bringing this up,
michael

-- 
http://michael-bien.com/