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

  • Home
  • SEARCH
  • 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 6968949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:31:06+00:00 2026-05-27T16:31:06+00:00

I am writing a program that can play .wav files with a click of

  • 0

I am writing a program that can play .wav files with a click of a button. Currently, I’ve been doing it like this:

  1. Load/Open file.
  2. Play file.
  3. Close file.

This happens in a separate thread.

This works quite well and I have no problems doing it but I’ve read somewhere that loading the files each time they are needed can potentially slowdown the program and may cause all sorts of troubles. They said it is smarter to put these files in a cache but I’m not sure how to do that (I think I read that in StackOverflow too but I’m not too sure).

Thanks in advance.

  • 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-27T16:31:07+00:00Added an answer on May 27, 2026 at 4:31 pm

    It depends how you play the file but assuming you load the file as a byte stream you’d just store the contents of the file as a byte array and put it into the cache.

    When loading the file again you retrieve the byte array from the cache and create an input stream from it.

    Something like this pseudo code:

    byte[] cachedFile = cache.get(filename);
    if( cachedFile != null ) {
       cachedFile = loadFile( filename);
       cache.put( filename, cachedFile );
    }
    
    InputStream stream = new ByteArrayInputStream(cachedFile);
    play(stream);
    

    Note that this is just some basic approach, you’d need to add synchronization to the cache access, exception handling, cache eviction strategies (if the cache might get too big) etc.

    Besides that you might look into memory mapping the files which provides a tradeoff: You don’t have to read the entire file before playing it but read the stream directly while playing. Thus you’d only read the parts that the player needs. This might still be slower than in-memory data due to lower hard disk throughput but that might not even be noticable since you only need a certain amount of data from the file at a given time. With this approach you wouldn’t need a cache and you’d reduce memory requirements.

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

Sidebar

Related Questions

I've been writing a program that can determine any and every data about an
I noticed that I can start a program with it's associated handler by writing
Maybe you can help me... I am writing a program in Windows Mobile that
I'm writing a program that can be used by multiple users and concurrency is
For about a year I have been thinking about writing a program that writes
I am writing a program that can be loaded by another service (under our
Writing a simple program that will find exact duplicate files on my computer, but
I'm writing a program that creates a Word document with sensitive information. I'd like
I'm writing a program which is supposed to read two strings that can contain
I am writing a program that stores data in a dictionary object, but this

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.