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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:43:04+00:00 2026-06-04T12:43:04+00:00

I am in a scratchbox cross compile environment and have this #include <stdio.h> #include

  • 0

I am in a scratchbox cross compile environment and have this

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    int * ptr;
    int i=0;

    while(1)
    {
        ptr = (int*)malloc( 10485760 * sizeof(int) );

        if(ptr == NULL)
        {
            printf("Could not malloc\n");
            exit(1);
        }

        else
        {
            printf("Malloc done\n");
            for (i = 0 ; i <= 10485759 ; i++)
            {
                ptr[i] = i ;
            }
            sleep (5);
            continue;
        }
    }
}

When I run the binary and do

ps -p pid -o cmd,rss,%mem

I do not see any increase in the memory footprint of the process. Why is that?

  • 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-04T12:43:06+00:00Added an answer on June 4, 2026 at 12:43 pm

    You probably built very optimized.

    On most modern systems gcc knows that malloc returns a non-aliased pointer. That is to say, it will never return the same pointer twice and it will never return a pointer you have saved ‘live’ somewhere else.

    I find this very very hard to imagine, but it is possible that malloc is being called once and its return value being used over and over. The reasons being:

    It knows your memory is a dead store. ie: you write to it, but it never gets read from. The pointer is known to not be aliased so it hasn’t escaped to be read from somewhere else, and it isn’t marked volatile. Your for loop itself /could/ get thrown away.

    At that point it could just use the same memory over and over.

    Now here is why I find it hard to believe: Just how much does gcc know about malloc? Malloc could have any kind of side effects like incrementing a global ‘number of times called’ to ‘paints my room a random shade of blue’. It seems really weird that it would drop the call and assume it to be side-effect-free. Hell, ‘malloc’ could be implemented to return NULL every 100th call (maybe not quite to spec, but who is to say).

    What it is NOT doing is freeing it on your behalf. That goes beyond what it ‘could’ know and into the territory of ‘doing things it’s just not allowed to’. You’re allowed to leak memory, lame though it may be.

    2 things would be useful here:
    1) Compile environmenet: which os, compiler, and command line flags.

    and 2) disassembly of the final binary. (objdump or from the compiler)

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

Sidebar

Related Questions

I have a simple C++ program: #include <iostream> int main() { std::cout << "Hello\n";
I'm using scratchbox 2, the maemo development cross-compilation environment. When compiling code for the
Has anyone successfully cross-compiled mono for ARM under Linux without scratchbox or qemu? (maybe
How to we setup scratchbox for android to do cross compilation?What type of target
I have what I assume is a fairly standard setup, with one scratchpad MOC
I am trying to compile Python 3.2 for an ARM920T (architecture 4T) but I
I have a makefile which does the usual directory creation: $(Release_target_OBJDIR)/%.o: %.cpp mkdir -p
Recent events on the blogosphere have indicated that a possible performance problem with Scala
the Android ndk is hard to use for the old autoconf based code, so
I want to port few C/C++ libraries to Android, how feasible it would be

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.