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

  • Home
  • SEARCH
  • 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 338299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:24:59+00:00 2026-05-12T10:24:59+00:00

My question specifically is in regards to arrays, not objects. There a few questions

  • 0

My question specifically is in regards to arrays, not objects.

There a few questions on SO about malloc()/free() versus new/delete, but all of them focus on the differences in how they are used. I understand how they are used, but I don’t understand what underlying differences cause the differences in usage.

I often hear C programmers say that malloc() and free() are costly operations, but I’ve never heard a C++ programmer say this about new and delete. I’ve also noticed that C++ doesn’t have an operation that corresponds to C’s realloc().

If I were writing an equivalent to C++’s vector class, I would want to avoid copying the entire array when resizing it, but with new and delete you have to copy. In C, I would simply realloc(). It’s worth noting that realloc() might just copy the entire array, but my impression was that it used the same pointer and allocated less space for it, at least when sizing down.

So my question is, how do the algorithms used by malloc() and free() differ from those used by new and delete. More specifically, why does the C way have a stigma of being more expensive, and why doesn’t the C++ way allow resizing without copying?

  • 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-12T10:25:00+00:00Added an answer on May 12, 2026 at 10:25 am

    There’s no real difference under the hood – usually the default new and delete operators will simply call through to malloc and free.

    As for “the stigma of being more expensive”, my theory is this: back in the day, every cycle counted, and the time taken by malloc really was significant in many situations. But by the time C++ came along, hardware was much faster and the time taken by the free store manager was proportionally less significant. The emphasis was shifting from efficient use of machine resources to efficient use of programmer resources.

    Why C++ lacks a realloc equivalent, I don’t know.

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

Sidebar

Related Questions

My question is specifically what I'm after, but I'm also interested in 'general rules'
One simple question (but I haven't quite found an obvious answer in the NLP
A user recently inquired (OK, complained) as to why a 19-digit account number on
I am making a game for windows, mac and GNU, I can built it
I love the ideas presented in Brian Kernighan and Rob Pike's book, The UNIX
I am animating sprites in a HTML/JavaScript game by showing/hiding/repositioning many divs, each with
what is the difference in the way these work: Sql = INSERT INTO mytable
Shouldn't we use Pixel for anything in CSS if we are making a site
[Serializable] class MyClass { [NonSerialized] int Foo { get; set; } // error [NonSerialized]
I'm having trouble running a full trust WPF 4 XBAP (browser application), created with

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.