2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_MALLOC_H_
|
|
|
|
|
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_MALLOC_H_
|
|
|
|
|
|
2012-09-29 03:49:36 +00:00
|
|
|
// The functions declared here
|
|
|
|
|
// 1) Allocates block of aligned memory.
|
|
|
|
|
// 2) Re-calculates a pointer such that it is aligned to a higher or equal
|
|
|
|
|
// address.
|
|
|
|
|
// Note: alignment must be a power of two. The alignment is in bytes.
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
|
2012-09-29 03:49:36 +00:00
|
|
|
#include "system_wrappers/interface/scoped_ptr.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
// Returns a pointer to the first boundry of |alignment| bytes following the
|
|
|
|
|
// address of |ptr|.
|
|
|
|
|
// Note that there is no guarantee that the memory in question is available.
|
|
|
|
|
// |ptr| has no requirements other than it can't be NULL.
|
|
|
|
|
void* GetRightAlign(const void* ptr, size_t alignment);
|
|
|
|
|
|
|
|
|
|
// Allocates memory of |size| bytes aligned on an |alignment| boundry.
|
|
|
|
|
// The return value is a pointer to the memory. Note that the memory must
|
|
|
|
|
// be de-allocated using AlignedFree.
|
|
|
|
|
void* AlignedMalloc(size_t size, size_t alignment);
|
|
|
|
|
// De-allocates memory created using the AlignedMalloc() API.
|
|
|
|
|
void AlignedFree(void* memBlock);
|
|
|
|
|
|
|
|
|
|
// Scoped pointer to AlignedMalloc-memory.
|
|
|
|
|
template<typename T>
|
|
|
|
|
struct Allocator {
|
|
|
|
|
typedef scoped_ptr_malloc<T, AlignedFree> scoped_ptr_aligned;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_ALIGNED_MALLOC_H_
|