Sign in to follow this  
riruilo

How to declare a queue of vector on Java?

Recommended Posts

Hi friends! How to declare a queue of vector (of byte, fixed size) on Java? I want just every element is a byte array of 64 elements. Something like this: (this does not work) Queue<byte[64]> m_queue = new LinkedList<byte[64]>(); Must I use another class? For instance: Queue<Vector64Byte> m_queue = new LinkedList<Vector64Byte>(); I wouldn't like to do that. Thanks a lot for suggestions.

Share this post


Link to post
Share on other sites
Java arrays' size is defined on allocation, not on declaration, so you can't have a pointer of a fixed size. You can create a Vector64Byte class, or you can do something like that:
[source lang=java]
public class LinkedList64Byte extends LinkedList<byte[]>
{
public void add(int index,byte[] element)
{
if(element.size!=64)
throw new WrongSizeException();
super.add(index,element);
}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by riruilo
Hi friends!

How to declare a queue of vector (of byte, fixed size) on Java?

I want just every element is a byte array of 64 elements.

Something like this: (this does not work)
Queue<byte[64]> m_queue = new LinkedList<byte[64]>();

Must I use another class? For instance:
Queue<Vector64Byte> m_queue = new LinkedList<Vector64Byte>();
I wouldn't like to do that.


I suspect you mean an array, not a vector. If you meant a vector located in a 64D space with only 8 bits of precision per axis, you should create its class.

If you meant array, arrays are not vectors, each array must be allocated by new. (And each array would have Object overhead.)
...
add(new byte[64]);
...

Should do the trick.

Also don't prefix your variables, it's not C, it's Java, and it was bad even in C. If you desperately need a name decorator for some real reason, use postfix decoration.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this