{"id":5322,"date":"2014-03-30T20:41:29","date_gmt":"2014-03-30T20:41:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/struct-pointer-not-providing-the-correct-size-in-sizeof-method-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:41:29","modified_gmt":"2014-03-30T20:41:29","slug":"struct-pointer-not-providing-the-correct-size-in-sizeof-method-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/struct-pointer-not-providing-the-correct-size-in-sizeof-method-collection-of-common-programming-errors\/","title":{"rendered":"Struct Pointer Not Providing the Correct Size in sizeof() method-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m having a issue getting the size of a struct pointer after allocating the memory using malloc or realloc. I&#8217;ve worked around this by keeping track of the memory in a separate counter, but I would like to know if this is a bug or if there is a way to properly query the size of a struct pointer.<\/p>\n<p>Sample code demonstrates that no matter how much memory I allocate to the struct pointer it always returns 4 when querying using the sizeof() method.<\/p>\n<pre><code>typedef struct {\n    int modelID;\n    int bufferPosition;\n    int bufferSize;\n} Model;\n\nModel *models = malloc(10000 * sizeof(Model));\n\nNSLog(@\"sizeof(models) = %lu\", sizeof(models)); \/\/this prints: sizeof(models) = 4\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m having a issue getting the size of a struct pointer after allocating the memory using malloc or realloc. I&#8217;ve worked around this by keeping track of the memory in a separate counter, but I would like to know if this is a bug or if there is a way to properly query the size [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5322","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5322"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5322\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}