3 ms·
#1) GetComputerNameA can fail. You didn't check the error message or convert it into a C++ exception. #2) You probably want GetComputerNameW. GetComputerNameA
by jiggawatts 6y ago
#1) GetComputerNameA can fail. You didn't check the error message or convert it into a C++ exception.
#2) You probably want GetComputerNameW. GetComputerNameA uses an unspecified encoding that you'd have to handle.
#3) A 1KB buffer is excessive! Over-sized buffers can blow through the L1 cache all too easily, slowing down applications. It's also stack allocated, and this can be a problem in some scenarios.
#4) You're forcing the computer name to be heap allocated. This can also be problematic in some scenarios, and is slower. GetComputerName might be used in logging scenarios that are already trying to handle cases such as "out of memory"! Allocating more memory may be unacceptable.
You get the idea.