There are many cases where copy_to_buffer will be used, but not all of them the copy_to_buffer is necessary. It is not necessary in particular one case:
- We do not need
source after "copying".
- The fields of
buffer is a subset of source.
In this case, numpy.lib.recfunctions.drop_fields is a better choice. Because we can directly overwrite source without worrying. Using drop_fields can help us save memory usage because there will be only one copy of the array existing in memory.
from numpy.lib.recfunctions import drop_fields
An example of this case is https://github.com/XENONnT/straxen/blob/5bb4e0494d02424ffb0563f758c6ffb644dfe4d8/straxen/plugins/records/records.py#L170-L171.
strax/strax/dtypes.py
Line 233 in b97cad2
There are many cases where
copy_to_bufferwill be used, but not all of them thecopy_to_bufferis necessary. It is not necessary in particular one case:sourceafter "copying".bufferis a subset ofsource.In this case,
numpy.lib.recfunctions.drop_fieldsis a better choice. Because we can directly overwritesourcewithout worrying. Usingdrop_fieldscan help us save memory usage because there will be only one copy of the array existing in memory.An example of this case is https://github.com/XENONnT/straxen/blob/5bb4e0494d02424ffb0563f758c6ffb644dfe4d8/straxen/plugins/records/records.py#L170-L171.