diff options
author | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 02:22:39 +0000 |
---|---|---|
committer | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-26 02:22:39 +0000 |
commit | 9f01b02c5cf73f601d53f3708bdd105b1626d4dd (patch) | |
tree | 3ab821f15c6a7474093c50ec85b8b1f89a8ac6eb /base/memory/aligned_memory_unittest.cc | |
parent | 4d14d9c53ff54dd3bfa56dd319cc45123d92e0bd (diff) | |
download | chromium_src-9f01b02c5cf73f601d53f3708bdd105b1626d4dd.zip chromium_src-9f01b02c5cf73f601d53f3708bdd105b1626d4dd.tar.gz chromium_src-9f01b02c5cf73f601d53f3708bdd105b1626d4dd.tar.bz2 |
Upgrade AlignedMemory to support dynamic allocations.
Adds two new methods: AlignedAlloc and AlignedFree for creating and
destroying dynamic aligned allocations respectively. Also adds a
helper class, ScopedPtrAlignedFree, for use with scoped_ptr_malloc.
AlignedAlloc uses posix_memalign for OS X (now that we're targeting
10.6), Linux and _aligned_alloc() on Windows. Android and NaCl use
memalign() since they do not expose posix_memalign() and memalign()
is safe to use with free() on those platforms.
Also hacks around a bug in Visual C++ where __alignof will sometimes
return zero:
http://connect.microsoft.com/VisualStudio/feedback/details/682695/c-alignof-fails-to-properly-evalute-alignment-of-dependent-types
BUG=none
TEST=base_unittests + new test, trybots.
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=147988
Review URL: https://chromiumcodereview.appspot.com/10796020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148483 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/memory/aligned_memory_unittest.cc')
-rw-r--r-- | base/memory/aligned_memory_unittest.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/base/memory/aligned_memory_unittest.cc b/base/memory/aligned_memory_unittest.cc index 8c1eb61..c337751 100644 --- a/base/memory/aligned_memory_unittest.cc +++ b/base/memory/aligned_memory_unittest.cc @@ -51,4 +51,33 @@ TEST(AlignedMemoryTest, StackAlignment) { #endif // !(defined(OS_IOS) && defined(ARCH_CPU_ARM_FAMILY)) } +TEST(AlignedMemoryTest, DynamicAllocation) { + void* p = base::AlignedAlloc(8, 8); + EXPECT_TRUE(p); + EXPECT_ALIGNED(p, 8); + base::AlignedFree(p); + + p = base::AlignedAlloc(8, 16); + EXPECT_TRUE(p); + EXPECT_ALIGNED(p, 16); + base::AlignedFree(p); + + p = base::AlignedAlloc(8, 256); + EXPECT_TRUE(p); + EXPECT_ALIGNED(p, 256); + base::AlignedFree(p); + + p = base::AlignedAlloc(8, 4096); + EXPECT_TRUE(p); + EXPECT_ALIGNED(p, 4096); + base::AlignedFree(p); +} + +TEST(AlignedMemoryTest, ScopedDynamicAllocation) { + scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> p( + static_cast<float*>(base::AlignedAlloc(8, 8))); + EXPECT_TRUE(p.get()); + EXPECT_ALIGNED(p.get(), 8); +} + } // namespace |