D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7271 - Calling struct.init causes a memory allocation.
Summary: Calling struct.init causes a memory allocation.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-11 09:03 UTC by Benjamin Thaut
Modified: 2012-07-04 11:04 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Benjamin Thaut 2012-01-11 09:03:33 UTC
struct MemoryBlockInfo
{
  size_t size;
  long[10] backtrace;
  int backtraceSize;

  this(size_t size)
  {
    this.size = size;
  }
}

int main(string[] argv)
{
  MemoryBlockInfo info;
  info = MemoryBlockInfo.init; //array allocation here
} 

This allocation seems totaly unneccesary. Also TypeInfo.init should return a immutable(void)[] instead of a void[] as it seems totaly illogical to modify the data retreived by TypeInfo.init.

This is especially critical when working without a GC because one is not able to free the allocated memory for the array as the allocation gets generated by the compiler.
Comment 1 Brad Anderson 2012-07-04 10:03:51 UTC
Discussion suggesting this is resolved and should be closed.

http://forum.dlang.org/post/jsmipc$17h7$1@digitalmars.com

I couldn't find the issue it was a duplicate of.
Comment 2 bearophile_hugs 2012-07-04 11:04:10 UTC
(In reply to comment #1)
> Discussion suggesting this is resolved and should be closed.

Now it's closed as fixed.


> I couldn't find the issue it was a duplicate of.

Maybe it was fixed fixing Issue 7243