1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CHRE_UTIL_MEMORY_H_ 18 #define CHRE_UTIL_MEMORY_H_ 19 20 namespace chre { 21 22 /** 23 * Destroys count objects starting at first. This function is similar to 24 * std::destroy_n. 25 * 26 * @param first Starting address of count objects to destroy 27 * @param count The number of objects to destroy 28 */ 29 template<typename ElementType> 30 void destroy(ElementType *first, size_t count); 31 32 /** 33 * Performs move assignment (dest = std::move(source)) if supported by 34 * ElementType, otherwise copy assignment (dest = source). 35 */ 36 template<typename ElementType> 37 void moveOrCopyAssign(ElementType& dest, ElementType& source); 38 39 /** 40 * Initializes a new block of memory by transferring objects from another block, 41 * using memcpy if valid for the underlying type, or the move constructor if 42 * available, or the copy constructor. This function is similar to 43 * std::uninitialized_move_n. 44 * 45 * @param source The beginning of the data to transfer 46 * @param count The number of elements to transfer 47 * @param dest An uninitialized buffer to be populated with count elements 48 */ 49 template<typename ElementType> 50 void uninitializedMoveOrCopy(ElementType *source, size_t count, 51 ElementType *dest); 52 53 } // namespace chre 54 55 #include "chre/util/memory_impl.h" 56 57 #endif // CHRE_UTIL_MEMORY_H 58