Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 504607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:30:48+00:00 2026-05-13T06:30:48+00:00

I’m in the process of making some changes to a library that I’m using.

  • 0

I’m in the process of making some changes to a library that I’m using. In order to reduce memory usage the library is writing its temporary data to disk instead of keeping it in memory. However, for my usage scenario it is more efficient to keep it in memory. It also has some concurrency issues, because it has constant names for its temp-files and can therefore not run concurrently in different threads (because the threads will corrupt each other’s data).

I therefore need to change the library so that it keeps all its data in memory instead. I have not originally written the library and I’m therefore not very comfortable with making drastic changes to the code. I’d therefore like to do this with as little refactoring as possible. The code which writes to disk is quite simple. Here’s a (somewhat simplified) example:

final FileChannel fileChannel = this.randomAccessFile.getChannel();
fileChannel.position(calculatePosition());
while (blockData.hasRemaining())
{
 fileChannel.write(blockData);
}

The reading of a block is very similar (i.e. it uses a FileChannel, which it gets from a RandomAccessFile).

It feels like the easiest solution would be if I can use some implementation of FileChannel, which maps to a place in memory instead of to a file. I know I can map a file to a place in memory using FileChannel’s map-method. However, that is the other way around. That gives me a “memory-API” to a file. I want a FileChannel-interface against some memory. Are there any available implementations of this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:30:48+00:00Added an answer on May 13, 2026 at 6:30 am

    Java 7 will allow pluggable filesystems, so you’ll be able to use a memory based filesystem and keep the current FileChannel API. Short of that you’re likely to have to change the API you use to Commons-VFS as Adrian suggests or use memory only structures.

    EDIT per the 2023 update to this question, asking if this can be done without external libraries… I suspect this is the wrong question, because FileChannel will always specifically be connected to a file object.

    FileChannel consists mostly of a set of implemented interfaces…

    In particular, you probably are interested in the functionality of
    ByteChannel or ReadableByteChannel or SeekableByteChannel, all of which have fairly small footprints. It would be pretty easy to create a ByteBufferChannel that implements one of those.

    Just write your code expecting a FileChannel to instead use the actual java Interface you care about, and you can pass either a FileChannel or the proposed ByteBufferChannel in interchangably.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.