Jump to content
  • Advertisement
Sign in to follow this  
riruilo

How to declare a queue of vector on Java?

This topic is 3474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!