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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:17:18+00:00 2026-05-20T14:17:18+00:00

I’m extracting frames of video to a Surface array to be rearranged into a

  • 0

I’m extracting frames of video to a Surface array to be rearranged into a new video, trading the x dimension with time. Here are some examples of different kinds of effects that come out: http://www.youtube.com/view_play_list?p=B2540182DE868E85

The app always crashes with std::bad_alloc when I try to store 1280 frames of 1280×720 video (1,179,648,000 pixels) into the Surface[]. It doesn’t crash with 1280 frames of 1080×720 video (995,328,000 pixels).

I made a simple test that makes it work on my computer (4GB RAM), but not on a friend’s wimpier laptop:

maxWidth = 1920;
while ((inW * inH * maxWidth) >= 1000000000)
  maxWidth -= 20;

Two questions:

  1. Is there a better way to have fast access to 10^9 pixels than a Surface array?
  2. What is this memory limit, and how can I test for it and avoid it when setting up the maxWidth for the output?

Big thanks from the C++ noob. I put the source on Github: Redimensionator. It uses Cinder.

  • 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-20T14:17:19+00:00Added an answer on May 20, 2026 at 2:17 pm

    First off, on a 32-bit platform, your hard limit for address space usage is going to be somewhere around 2GB (but possibly much less) – assuming you keep it all mapped at once. It’s best to assume you won’t be able to get more than maybe 512MB in contiguous memory, and 1-1.5GB or so in noncontiguous memory (ie, by making multiple small mappings). This is most likely the problem you have; you ran out of contiguous address space. The hardware in turn is limited (for intel CPUs) to somewhere around 16GB of memory for a 32-bit system. And you really, really don’t want to be swapping. So this means you have one of several options:

    • Use a 64-bit system, and a really big array (simple and fast, requires a lot of memory).
    • Use a 32-bit system, and a hack to get around address space limits. This tends to mean you’ll need to create shared memory objects, and map in only part of the space at a time. On Windows, you can use an anonymous file mapping object for this – basically shared memory with a NULL name. On Linux, you’ll need to first increase the maximum size of /dev/shm, then use shm_open and mmap. (complex, almost as fast as the 64-bit one if done right. Minimize the number of remappings you do. Still needs a lot of memory)
    • Use disk files. Only a real option with a SSD; on a real disk the seeking will take far too long to be practical. Basically you’d just seek around the file and write out columns of data at a time. (Relatively slow, but not too complex. Requires a SSD. Minimal memory requirements)
    • Make multiple passes. You can select a group of output frames to hold in memory at a time; decode the entire video, skipping the parts that correspond to frames you’re not holding in memory yet. Once you complete the current set of frames, write them to disk and start over, decoding the video from scratch, with a new set of output frames. This is well suited to massive parallelism – you can break each output set off to another seperate computer to do the work, then stitch them all together in the end. (moderately complex; slow; trades CPU time for memory. Can be very fast if parallelized).

    The first two options are good if you have enough memory to hold the entire output video. Ideally you’d want to go the 64-bit route; remapping shared memory windows is an expensive operation, and you’ll be doing it a lot.

    With the fourth option, it can be difficult to know what the memory limit is. I would recommend doing a binary search using test allocations to figure out how much space in your address space you can use (you should be using low level allocation calls to avoid heap overhead, note). Note that if you’re not careful this might not leave any address space for your video decoder – it’d probably be best to subtract 100mb or so from the result and reallocate it to give some room for the normal heap. You should also be careful to stay well below total physical memory, to avoid hitting swap.

    Without knowing your OS and what library you’re getting that Surface class from, it’s hard to be more specific about how to probe it – but you really should avoid keeping it in the normal heap, just to avoid allocation errors in other code that’s possibly not instrumented to deal with OOMs.

    As a side note, you may want to rotate the output frames 90 degrees while preparing them (that is, put them into column major order). You can then rotate them back as a final pass after constructing all the raw images (or even when encoding from raw image data to a compressed format). This is especially important if you decide to go with the disk route with a SSD – it will help avoid unnecessary reads and writes, as with row major order (the usual order for videos) you will have to skip over the pixels for other columns whenever you write one. With in-memory work, though, it’s still helpful, as it improves cache locality.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.