- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I declare and initialize objects with:
WCHAR MyString[1024] = {};
AStruct MyStructure = {};
The Intel compiler actually places a block of memory the size of the struct or array filled with '0' in the rdata section and copies the zeros into the object at run time... This behavior is bloating my compiled binary.
The Microsoft compiler handles these initializations by doing a memset to zero on the new object. Is there a flag or option to have the Intel compiler use memset versus statically allocating the zeros and copying them on initialization?
Thanks!!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a specific full code example:
#include <stdio.h> typedef struct bigStruct{ char aList[2048]; }bigStruct; int main(){ bigStruct myStruct; // No additional static zeros in the compiled binary //bigStruct myStruct = bigStruct(); // No additional static zeros in the compiled binary //bigStruct myStruct = {}; // sizeof(bigStruct) zeros added to the compiled binary //bigStruct myStruct = { 0 }; // sizeof(bigStruct) zeros added to the compiled binary //bigStruct myStruct{}; // sizeof(bigStruct) zeros added to the compiled binary for (int i = 0; i < (sizeof(myStruct.aList) / sizeof(char)) - 1; ++i){ printf("Char Val %d, Index %d\n",myStruct.aList,i); myStruct.aList = 0; } return 0; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suppose you would need to do this explicitly by removing the initializer and writing in the memset or fill() or using new and value initialization.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
typedef struct bigStruct{ char aList[2048]; bigStruct() { memset(aList, 0, sizeof(*this)); } } bigStruct; Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jim's suggestion may need -Qansi-alias to optimize. That became a default in icpc 15.0 for linux.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tim,
Oops, Correction
memset(this, 0, sizeof(*this);
This is for use with POD objects that you need to zero.
Do not use if encapsulated struct/class objects are not POD.
I've been using that since ~1992. (Borland Turbo C++)
Jim Dempsey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page