C ++ allocator <X> :: deallocate (NULL, 1) resolved?

Both free(NULL) and ::operator delete(NULL) allowed. Is the concept of a dispenser (for example, std :: allocator also allow deallocate(NULL,1) ), or is it necessary to place your own guard around yourself?

+6
c ++ memory-management null free allocator
source share
1 answer

You will need to add your own validation.

According to ยง20.4.1.18, deallocate required:

p must be a pointer value obtained from allocate (). n must equal the value passed as the first argument to call the highlight that p returned.

allocate throws an exception if storage cannot be provided (ยง20.4.1.1 / 7). In other words, allocate never returns 0, and therefore deallocate should never have 0. Passing 0 will result in undefined behavior.

+9
source share

All Articles