• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

bit shift question.

 
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try looking at buffer.length to see if you did it right.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
O ya.. I'll keep that in mind... use integers instead ! : ) thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic