srec file.

Posted on 2005-04-27
Last Modified: 2010-05-18
I have needs for an 'srec' file.  To do this, I thought perhaps I could first create a binary file, then convert the file to srec using a 'tool' called objcopyppc.

So now:

int main()
  char mbyte[ 1048576];
  std::ofstream ofile( "bigfile.bin" );
  int i = 0;
  int m = 0;
  std::cout << "how many MiB shall I write? ";
  std::cin >> m;

  for( i = 0; i < m; ++i )
       ofile.write( (char*)mbyte, sizeof mbyte );

  return 0;

I'll need to tweak the code above to ask the user to select a pattern. ie.  Choose betwen all zeros, or all ones or a counting pattern (1, 2, 3, .. ).
Conversly is it possible to just write code that'll generate the srec file withouth going through all this.  

Question by:forums_mp
    LVL 4

    Expert Comment

    Update your code
    std::ofstream ofile( "bigfile.bin" ,ios::out | ios::binary); //Otherwise file considers as text file

    intialize mbyte with data


    I don't know what you are going to do. Means I don't know about srec ....

    Author Comment


    Actually, I discovered that what I needed to do was a lot simpler than what I proposed in my initial post.   So revisiting.  I need to create a 64 MiB file with all ones or zeros.   I'm working with 'two environments'.  Visual Studio. NET and Tornado.  

    So now step 1.

    Within visual studio, I create this simple program that'll create a 28 Byte size file.  

    # include<iostream>
    # include<iomanip>

    #define MAX  7

    int main( void )
       std::cout << std::endl; std::cout << std::endl;
       std::cout << "# include<iostream> " << std::endl;
       std::cout << "# define MAX  " << MAX << std::endl;
       std::cout << std::endl; std::cout << std::endl;

       std::cout << " int huge_array[" << MAX << "] = {" << std::endl;
       for (int idx(0); idx < MAX - 1; ++idx)
             std::cout << std::setw(15)
                       << "   0xFFFFFFFF, "
    //                   << "   0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF  "
                             << std::endl;

       std::cout << "   0xFFFFFFFF " << std::endl;
       std::cout << " } " << std::endl;
       std::cout << std::endl; std::cout << std::endl;
       std::cout << " int main() " << std::endl;
       std::cout << " { " << std::endl;
       std::cout << " } " << std::endl;

    Lets assume executable is test.exe.  

    Step 2.

    From the command line I do:
     c:\test_project\Debug\test.exe >  test.c

    Now test.c looks like:

    # include<iostream>
    # define MAX  7

     int huge_array[7] = {

     int main()

    Step 3.

    I move over to tornado and execute/run test.c.  I end up with an object file (.o) thats 28 bytes.
    I then use that 28 byte file to create my srec file.

    You see, the Visual studio approach is a way for me to 'cheat' in terms of creatign the array.  i.e instead of typing huge_array's parameters by hand, I just use cout.   Now here's the trouble spot.  For a 64 MiB file MAX needs to be (16777216).   When I do
    c:\test_project\Debug\test.exe >  test.c.  This takes time.  Furthermore, when I opt to open test.c within tornado or any text editor etc.  I get memory errors (pc has no memory).  

    I'm not sure what to do here?
    LVL 5

    Accepted Solution

    Closed, 75 points refunded.
    Site Admin

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now