fromGoogleCode / mclinker

Automatically exported from code.google.com/p/mclinker
Other
0 stars 0 forks source link

[code quality] mcld mixes malloc/new in various places #147

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
grep malloc yields these occurences :-

./lib/ADT/StringEntry.cpp:  char* data = (char*)malloc(pVal.size()+1);
./lib/ADT/StringEntry.cpp:  char* data = (char*)malloc(length+1);
./lib/Target/X86/X86PLT.cpp:  data = static_cast<unsigned 
char*>(malloc(plt0->size()));
./lib/Target/X86/X86PLT.cpp:    data = static_cast<unsigned 
char*>(malloc(plt1->size()));
./lib/Target/X86/X86PLT.cpp:  data = static_cast<unsigned 
char*>(malloc(plt0->size()));
./lib/Target/X86/X86PLT.cpp:    data = static_cast<unsigned 
char*>(malloc(plt1->size()));
./lib/Target/Hexagon/HexagonPLT.cpp:  data = static_cast<unsigned 
char*>(malloc(plt0->size()));
./lib/Target/Hexagon/HexagonPLT.cpp:    Out = 
static_cast<uint32_t*>(malloc(HexagonPLT1::EntrySize));
./lib/Target/ARM/ARMPLT.cpp:  data = 
static_cast<uint32_t*>(malloc(ARMPLT0::EntrySize));
./lib/Target/ARM/ARMPLT.cpp:    Out = 
static_cast<uint32_t*>(malloc(ARMPLT1::EntrySize));
./lib/LD/ResolveInfo.cpp:                          
malloc(sizeof(ResolveInfo)+pKey.size()+1));
./lib/LD/ResolveInfo.cpp:                          malloc(sizeof(ResolveInfo) + 
1));
./lib/Support/Space.cpp:      // malloc
./lib/Support/Space.cpp:      memory = (void*)malloc(size);

Just trying to understand the reasoning.

Original issue reported on code.google.com by shanka...@gmail.com on 16 May 2013 at 3:55

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
We can separate new operator into some actions:
allocate memory from heap, to call the constructor from the starting address.

For Space.cpp, this is used to save the construction time.
For ResolveInfo: We use a trick to keep every thing in the same cache line. 
This code also fails -Wpedantic.
For StringEntry, this is also a trick to improve spatial locality. 
For backends's PLT, I think it's OK to use new to replace the malloc.

Original comment by LubaTang on 16 May 2013 at 6:52

GoogleCodeExporter commented 9 years ago

Original comment by pete.c...@gmail.com on 18 Sep 2013 at 11:26