I use a variable size C structure as shown below:
typedef struct { int num_elems; int elem1; } mystruct; // say I have 5 elements I would like to hold. mystruct * ms = malloc(sizeof(mystruct) + (5-1) * sizeof(int)); ms->num_elems = 5; // ... assign 5 elems and use struct free(ms);
Will it be the last free () free all that was malloc'd, or just sizeof (mystruct)?
Yes. This will free the entire block that was allocated with malloc.
malloc
If you allocate one block of memory with malloc(as in your example), you need to call freeexactly once to free this whole block.
free
, , , , , , malloc malloc.
, , malloc'd, , , , SIGSEV SIGBUS, , .
, , , , , .
Source: https://habr.com/ru/post/1756831/More articles:Clip with MongoMapper in Rails 3 - ruby-on-railsReasonable text layout in Android? - javaDevelop remotely in Xcode using iPad and VNC / RDP - xcodeJPA: problem with persisting foreign key - java-eeИспользование popen для записи в трубе посылает только данные, когда труба закрыта - c++Outlook 2010 ignores VALARM Web Calendar (ICS) created by my application - asp.net-mvcПочему мои уведомления иногда стираются с помощью рингтона с SD-карты? - androidNavigating and reading XML using C # 4.0 speaker? - xmlLoading classes that are not in the classpath - javajQuery and LinkButtons, or regular buttons and CSS - jqueryAll Articles