What's the standard for dynamically allocating memory?

dilan johnson <[email protected]> Mon, 1 Dec 2025 19:07:59 -0500
Newsgroups org.kernel.vger.linux-newbie
Message-ID <LV8P221MB1399D71143E168BBF9D9C955C3D8A@LV8P221MB1399.NAMP221.PROD.OUTLOOK.COM>
Hey all.

I just got interested in kernel development and I want to ask, what is 
the standard way to implement dynamically allocated memory?  I am trying 
to finish a todo and just want to know how the standard way to do it is 
so I don't write a bunch of code completely wrong, get yelled at and 
have to redo it.

Would it be something like this for an array of ints for example? 
(pseudocode)

struct dynarray {

         int *arraypointer;

         int arraysize;

         int used;

}


void cpy_to_dynarray(struct dynarray *dest, int *src, int size)

{

         if (size > dest->arraysize) {

                 dest->arraypointer = realloc(size * 2);

                 dest->arraysize = size * 2;

         }

          memcpy(dest->arraypointer, src, size);

}