1 // natDirectByteBufferImpl.cc
3 /* Copyright (C) 2003, 2004 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
18 #include <gnu/gcj/RawData.h>
19 #include <java/nio/VMDirectByteBuffer.h>
21 using gnu::gcj::RawData
;
24 java::nio::VMDirectByteBuffer::allocate (jint capacity
)
26 return reinterpret_cast<gnu::gcj::RawData
*> (::malloc (capacity
));
30 java::nio::VMDirectByteBuffer::free (gnu::gcj::RawData
* address
)
32 ::free (reinterpret_cast<void*> (address
));
36 java::nio::VMDirectByteBuffer::get (RawData
* address
, jint index
)
38 jbyte
* pointer
= reinterpret_cast<jbyte
*> (address
) + index
;
43 java::nio::VMDirectByteBuffer::get (RawData
* address
, jint index
,
44 jbyteArray dst
, jint offset
, jint length
)
46 jbyte
* src
= reinterpret_cast<jbyte
*> (address
) + index
;
47 memcpy (elements (dst
) + offset
, src
, length
);
51 java::nio::VMDirectByteBuffer::put (gnu::gcj::RawData
* address
,
52 jint index
, jbyte value
)
54 jbyte
* pointer
= reinterpret_cast<jbyte
*> (address
) + index
;
59 java::nio::VMDirectByteBuffer::adjustAddress (RawData
* address
, jint offset
)
61 jbyte
* start
= reinterpret_cast<jbyte
*> (address
) + offset
;
62 return reinterpret_cast<RawData
*>(start
);
66 java::nio::VMDirectByteBuffer::shiftDown (RawData
* address
, jint dst_offset
,
67 jint src_offset
, jint count
)
69 jbyte
* dst
= reinterpret_cast<jbyte
*> (address
) + dst_offset
;
70 jbyte
* src
= reinterpret_cast<jbyte
*> (address
) + src_offset
;
71 ::memmove(dst
, src
, count
);