wood burning stoves*
The moose likes Java in General and the fly likes bit shift question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "bit shift question." Watch "bit shift question." New topic
Author

bit shift question.

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

Am I doing this correct ?



I wanted to confirm if I am using the bit shift operators correctly.

1) In the first part, does it mean byte[] buffer = new byte[16 * 2 to the power 16] ? what is the memory size ?
2) In the second part what buffer size am I allocating ?

Am I at risk of running out of memory in any case if say I have 3 threads running each handling a 800 MB file ?

Thanks in advance.


Time is what we want the most, but what we use the worst. -- William Penn
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Try looking at buffer.length to see if you did it right.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
Yes, 16 << 16 is 16 * 1^16. But surely you would use hex and write 0x10?
Try this

As for the bit about memory, that is hardly a "beginning" topic, so I shall move this thread.>
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
I earlier wrote: . . . I shall move this thread.
. . . and I presume you found the mistakes in my posting?
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

yes got the mistakes, thanks for the reply : ) ,

now getting back to the memory issues ?



2) In the second part what buffer size am I allocating ?

Am I at risk of running out of memory in any case if say I have 3 threads running each handling a 800 MB file ?



Any help would be appreciated...
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18538
    
  40

Robin John wrote:


2) In the second part what buffer size am I allocating ?

Am I at risk of running out of memory in any case if say I have 3 threads running each handling a 800 MB file ?



Any help would be appreciated...



Why don't you tell us? .. in this topic, it was recommended that ... (1) you print out the buffer length, (2) you print out the value calculated from the expression, or (3) you work out the math on paper. Each of these options are easy and can be done in a few minutes.

As for running out of memory, we don't know the amount of memory of your machine, nor how much heap you have configured for your JVM.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

32-bit system

VM arguments - min heap 1024 and max 1600

2GB RAM

please let me know if you need more info ?

and I meant to quote only the memory part... before I could edit it.. you have replied : )

Thanks.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18538
    
  40

Robin John wrote:
and I meant to quote only the memory part... before I could edit it.. you have replied : )


Well, what was the result? The number of elements in the byte array should tell you closely, the memory that your application needs (just for the array).

Henry
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why are you bothering using a shift, anyway?
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

: ) hey David,

I dont know.. what legacy application I'm maintaining.. they want everything to be consistent : D through out the code...

I think its cool : )


Regards.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

In this case, it's only cool if it actually accomplishes something useful, which it doesn't: back before optimizing compilers, when we were writing in assembly, etc. a shift made sense. That hasn't been the case for quite some time now.
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

O ya.. I'll keep that in mind... use integers instead ! : ) thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bit shift question.
 
Similar Threads
Using Apache Commons Codec
Write a String to ByteArrayOutputStream
Transferring file name then file data over socket
file transfer over TCP problem
inserting data in to blob...