1

With regards to Expanding Java Memory-Mapped Byte Buffer, why doesn't the buffer expand upon writing past the limit? There isn't even a way to implement the behavior apparently without remapping the buffer. This also seems somewhat strange to me because I'd imagine that a few developers have wanted it, or is this just using the buffer in the wrong way?

Community
  • 1
  • 1
Sarah Szabo
  • 10,345
  • 9
  • 37
  • 60

1 Answers1

2

A MappedByteBuffer is a ByteBuffer is a Buffer, which has a fixed capacity defined on creation. So the semantics of Buffer prevent it.

As @SotiriosDelimanolis and @fge mention, the operating system semantics also prevent it. The memory mapping is created with a fixed size, and if you address beyond that size at the native level you will get a SIGSEGV.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    Does the concept of a memory-mapped file also prevent it? For example, what would it mean to the OS for a process to try and write bytes past the memory allocated for the mmap? – Sotirios Delimanolis Jan 14 '15 at 00:13