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 6555703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:51:08+00:00 2026-05-25T12:51:08+00:00

I am using a windows mobile compact edition 6.5 phone and am writing out

  • 0

I am using a windows mobile compact edition 6.5 phone and am writing out binary data to a file from bluetooth. These files get quite large, 16M+ and what I need to do is to once the file is written then I need to search the file for a start character and then delete everything before, thus eliminating garbage. I cannot do this inline when the data comes in due to graphing issues and speed as I get alot of data coming in and there is already too many if conditions on the incoming data. I figured it was best to post process. Anyway here is my dilemma, speed of search for the start bytes and the rewrite of the file takes sometimes 5mins or more…I basically move the file over to a temp file parse through it and rewrite a whole new file. I have to do this byte by byte.

private void closeFiles() {
    try {

    // Close file stream for raw data.
    if (this.fsRaw != null) {
        this.fsRaw.Flush();
        this.fsRaw.Close();

        // Move file, seek the first sync bytes, 
        // write to fsRaw stream with sync byte and rest of data after it
        File.Move(this.s_fileNameRaw, this.s_fileNameRaw + ".old");
        FileStream fsRaw_Copy = File.Open(this.s_fileNameRaw + ".old", FileMode.Open);
        this.fsRaw = File.Create(this.s_fileNameRaw);

        int x = 0;
        bool syncFound = false;

        // search for sync byte algorithm
        while (x != -1) {
            ... logic to search for sync byte
            if (x != -1 && syncFound) {
                this.fsPatientRaw.WriteByte((byte)x);
            }
        }

        this.fsRaw.Close();

        fsRaw_Copy.Close();
        File.Delete(this.s_fileNameRaw + ".old");
    }


    } catch(IOException e) {
        CLogger.WriteLog(ELogLevel.ERROR,"Exception in writing: " + e.Message);
    }
}

There has got to be a faster way than this!

————Testing times using answer ————-

Initial Test my way with one byte read and and one byte write:

27 Kb/sec

using a answer below and a 32768 byte buffer:

321 Kb/sec

using a answer below and a 65536 byte buffer:

501 Kb/sec
  • 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-25T12:51:09+00:00Added an answer on May 25, 2026 at 12:51 pm

    You’re doing a byte-wise copy of the entire file. That can’t be efficient for a load of reasons. Search for the start offset (and end offset if you need both), then copy from one stream to another the entire contents between the two offsets (or the start offset and end of file).

    EDIT

    You don’t have to read the entire contents to make the copy. Something like this (untested, but you get the idea) would work.

    private void CopyPartial(string sourceName, byte syncByte, string destName)
    {
        using (var input = File.OpenRead(sourceName))
        using (var reader = new BinaryReader(input))
        using (var output = File.Create(destName))
        {
            var start = 0;
            // seek to sync byte
            while (reader.ReadByte() != syncByte)
            {
                start++;
            }
    
            var buffer = new byte[4096]; // 4k page - adjust as you see fit
    
            do
            {
                var actual = reader.Read(buffer, 0, buffer.Length);
                output.Write(buffer, 0, actual);
            } while (reader.PeekChar() >= 0);
        }
    
    }
    

    EDIT 2

    I actually needed something similar to this today, so I decided to write it without the PeekChar() call. Here’s the kernel of what I did – feel free to integrate it with the second do...while loop above.

                var buffer = new byte[1024];
                var total = 0;
    
                do
                {
                    var actual = reader.Read(buffer, 0, buffer.Length);
                    writer.Write(buffer, 0, actual);
                    total += actual;
                } while (total < reader.BaseStream.Length);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm uploading a SQL Server CE compact database file from a Windows Mobile application
I am using C# in Windows Mobile 5. The program downloads large files from
I'm using compact framework/C# on windows mobile. In my application I am uploading data
i am using compact frame work for my windows mobile application in which i
Using Windows Mobile 6.5 and C# The CharacterCasing property seems to be missing from
I want to use gestures on a windows mobile phone. For example (using .net
How to apply scrollbar to windows mobile application using .net compact framework, and windows
I'm developing a application for Windows Mobile using C#(.Net Compact Framework 3.5), but I
I'm developing a Windows Mobile 5.0 and above application using .Net Compact Framework 2.0
Looking for a control for selecting a directory in Windows Mobile (using .NET Compact

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.