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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:57:43+00:00 2026-06-07T04:57:43+00:00

I am writing to a file, using a memory buffer. I copy each record

  • 0

I am writing to a file, using a memory buffer. I copy each record to the memory buffer and then flush it to the disk.

CODE:

    char * OutBuffer;
    char *pt;
    OutBuffer = new char(BufferSize);
    pt = OutBuffer;

    for (int i=0; i<(FileSize / RECORD_SIZE); i++){
        if (((i % recordsPerBlock)==0) && (i>0)){
           FileSortHandle->write(OutBuffer, BufferSize);
           pt = OutBuffer;
        }
        else{
           memcpy(pt, minRecord, RECORD_SIZE);
           pt = pt + RECORD_SIZE;
        }
           minRecord = nullptr;
    }

When i call “FileSortHandle->write(OutBuffer, BufferSize);” the VS shows:

“Windows has triggered a breakpoint in STL_Test2.exe.

This may be due to a corruption of the heap, which indicates a bug in STL_Test2.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while STL_Test2.exe has focus.

The output window may have more diagnostic information.”

Does anyone can help me?

  • 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-06-07T04:57:44+00:00Added an answer on June 7, 2026 at 4:57 am
    OutBuffer = new char(BufferSize);
    

    This allocates memory for just ONE char, and this one char is initialized with BufferSize which may cause overflow if BufferSize is too big for char.

    What you probably meant is this:

    OutBuffer = new char[BufferSize]; //use square brackets!
    

    It allocates memory for BufferSize chars. The buffer is uninitialized.


    It is not related to your problem, but if possible, prefer allocating the memory when you declare the pointer:

    char * OutBuffer = new char [BufferSize];
    char *pt = OutBuffer; //prefer initialization over assignment
    

    That is, prefer initialization over assignment.

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

Sidebar

Related Questions

I'm writing to a text file using the following declaration: void create_out_file(char file_name[],long double
I am writing a mex-file (using C++) that will accept a memory address as
I am writing to binary file using fstream and when open the file using
I am writing a XML file into a HTML file using JavaScript. Here is
When I am writing a file into GridFS using grid.put(), which has the same
I am writing the below structure in to the file using Binary Writer. File
I'm writing a script to parse a KML file using JAXB and MOXy, but
How can I write data to stdout instead of writing file? I'm using GPG
I'm populating an XElement with information and writing it to an xml file using
I am writing a Perl script (in Windows) that is using File::Find to index

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.