* Implemented a simple version of the private function mstats() (BeIDE needs it).
* Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16800 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
04cec2bbbd
commit
579c74ceb5
@ -1,21 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2002-2006, Haiku Inc. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
#ifndef _MALLOC_H
|
#ifndef _MALLOC_H
|
||||||
#define _MALLOC_H
|
#define _MALLOC_H
|
||||||
/*
|
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
// ToDo: there are some BeOS specific things missing, most
|
|
||||||
// things are only rarely or almost never used, though.
|
|
||||||
// The more important missing functionality *and* prototypes
|
|
||||||
// are mcheck(), mstats(), and malloc_find_object_address().
|
|
||||||
//
|
|
||||||
// Also, MALLOC_DEBUG is currently not yet supported.
|
|
||||||
//
|
|
||||||
// If you want to implement it, have a look at the BeOS header
|
|
||||||
// file malloc.h located in /boot/develop/headers/posix.
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -1,25 +1,22 @@
|
|||||||
///-*-C++-*-//////////////////////////////////////////////////////////////////
|
/*
|
||||||
//
|
* Copyright 2002-2006, Haiku Inc.
|
||||||
// Hoard: A Fast, Scalable, and Memory-Efficient Allocator
|
* Distributed under the terms of the MIT License.
|
||||||
// for Shared-Memory Multiprocessors
|
*/
|
||||||
// Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
|
|
||||||
//
|
|
||||||
// Copyright (c) 1998-2000, The University of Texas at Austin.
|
|
||||||
//
|
|
||||||
// This library is free software; you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Library General Public License as
|
|
||||||
// published by the Free Software Foundation, http://www.fsf.org.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful, but
|
|
||||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// Library General Public License for more details.
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/* Implementations of malloc(), free(), etc. in terms of hoard.
|
/* Hoard: A Fast, Scalable, and Memory-Efficient Allocator
|
||||||
* This lets us link in hoard in place of the stock malloc
|
* for Shared-Memory Multiprocessors
|
||||||
* (useful to test fragmentation).
|
* Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
|
||||||
|
*
|
||||||
|
* Copyright (c) 1998-2000, The University of Texas at Austin.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
* published by the Free Software Foundation, http://www.fsf.org.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@ -203,35 +200,8 @@ getAllocator(void)
|
|||||||
return theAllocator;
|
return theAllocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
void * operator new (size_t size)
|
|
||||||
{
|
|
||||||
return HOARD_MALLOC (size);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
void * operator new (size_t size, const std::nothrow_t&) throw() {
|
|
||||||
return HOARD_MALLOC (size);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void * operator new[] (size_t size)
|
|
||||||
{
|
|
||||||
return HOARD_MALLOC (size);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
void * operator new[] (size_t size, const std::nothrow_t&) throw() {
|
|
||||||
return HOARD_MALLOC (size);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void operator delete (void * ptr)
|
|
||||||
{
|
|
||||||
HOARD_FREE (ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator delete[] (void * ptr)
|
// #pragma mark - public functions
|
||||||
{
|
|
||||||
HOARD_FREE (ptr);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" void *
|
extern "C" void *
|
||||||
@ -329,3 +299,50 @@ realloc(void *ptr, size_t size)
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - BeOS specific extensions
|
||||||
|
|
||||||
|
|
||||||
|
struct mstats {
|
||||||
|
size_t bytes_total;
|
||||||
|
size_t chunks_used;
|
||||||
|
size_t bytes_used;
|
||||||
|
size_t chunks_free;
|
||||||
|
size_t bytes_free;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" struct mstats mstats(void);
|
||||||
|
|
||||||
|
extern "C" struct mstats
|
||||||
|
mstats(void)
|
||||||
|
{
|
||||||
|
// Note, the stats structure is not thread-safe, but it doesn't
|
||||||
|
// matter that much either
|
||||||
|
processHeap *heap = getAllocator();
|
||||||
|
static struct mstats stats;
|
||||||
|
|
||||||
|
int allocated = 0;
|
||||||
|
int used = 0;
|
||||||
|
int chunks = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < hoardHeap::SIZE_CLASSES; i++) {
|
||||||
|
int classUsed, classAllocated;
|
||||||
|
heap->getStats(i, classUsed, classAllocated);
|
||||||
|
|
||||||
|
if (classUsed > 0)
|
||||||
|
chunks++;
|
||||||
|
|
||||||
|
allocated += classAllocated;
|
||||||
|
used += classUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.bytes_total = allocated;
|
||||||
|
stats.chunks_used = chunks;
|
||||||
|
stats.bytes_used = used;
|
||||||
|
stats.chunks_free = hoardHeap::SIZE_CLASSES - chunks;
|
||||||
|
stats.bytes_free = allocated - used;
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user