Dynamic memory allocation in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Devendra Mandan
    New Member
    • Oct 2011
    • 1

    Dynamic memory allocation in C

    I didn't understand that in dma ,are we required to have an initial guess of the memory needed or the calloc function allocates it as we need more of it i.e; what if our guess was not correct?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You aren't required to "have a guess". You are required to know exactly how much memory you require.

    If you don't know how much you need right now then either
    1. You are trying to allocate memory too early
    2. You know you need X bytes now you might need more later. Then allocate X bytes and set your data structures up so that later you can allocate more if required.

    Comment

    Working...