Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bit shift question.

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try looking at buffer.length to see if you did it right.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50232
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50232
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I earlier wrote: . . . I shall move this thread.
. . . and I presume you found the mistakes in my posting?
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you bothering using a shift, anyway?
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
: ) 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O ya.. I'll keep that in mind... use integers instead ! : ) thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic