CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    6

    Red face Allocate disc space

    Ok, here is the problem, I want to try running functions on large files to see how long the will take to run, but I don't want to make huge text files and run the functions against them. Is there a way to allocate memory, let's say 100mb and then run a function on those bytes/bits? (the content doesn't matter)

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Allocate disc space

    It would not be an acurate test, If you need to check the speed of processing large files then you should work with large files. Memory is much faster that file i/o

    Surely you have some large files already on the system
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: Allocate disc space

    DataMiser is correct. However, should you still want to pursue this, you may find MemoryStream (link) to be useful. In short, it is a Stream (like a filestream) that is backed by a byte array.

    Hope that helps!
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Allocate disc space

    With the respect to DataMiser's point, I've used following unmanaged methods to (de)allocate large amout of memory
    Code:
     IntPtr p = Marshal.AllocHGlobal(size);
     Marshal.FreeHGlobal(p);
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured