mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
visual studio
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@2559 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
parent
fa6a5bfc35
commit
a042aad7f2
@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Version="9.00"
|
||||
Name="processLexicalTable"
|
||||
ProjectGUID="{9834EABB-2033-4607-9DAC-36D16E0725B5}"
|
||||
RootNamespace="processLexicalTable"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
@ -61,10 +62,12 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies=""$(SolutionDir)\$(ConfigurationName)\moses.lib" zlib.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -85,9 +88,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -136,12 +136,14 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies=""$(SolutionDir)\$(ConfigurationName)\moses.lib" zlib.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -162,9 +164,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -214,12 +213,14 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/FORCE:MULTIPLE"
|
||||
AdditionalDependencies=""$(SolutionDir)\$(ConfigurationName)\moses.lib" zlib.lib dstruct.lib flm.lib lattice.lib misc.lib oolm.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -240,9 +241,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -294,10 +292,12 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/FORCE:MULTIPLE"
|
||||
AdditionalDependencies=""$(SolutionDir)\$(ConfigurationName)\moses.lib" zlib.lib dstruct.lib flm.lib lattice.lib misc.lib oolm.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -318,9 +318,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Version="9.00"
|
||||
Name="processPhraseTable"
|
||||
ProjectGUID="{AA230564-6DF1-4662-9BF9-7AD73DE53B76}"
|
||||
RootNamespace="processPhraseTable"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
@ -61,10 +62,12 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies=""$(SolutionDir)\$(ConfigurationName)\moses.lib" zlib.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -85,9 +88,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -136,12 +136,14 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies=""$(SolutionDir)\$(ConfigurationName)\moses.lib" zlib.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -162,9 +164,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -214,12 +213,14 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/FORCE:MULTIPLE"
|
||||
AdditionalDependencies=""$(SolutionDir)\$(ConfigurationName)\moses.lib" zlib.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -240,9 +241,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -294,10 +292,12 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/FORCE:MULTIPLE"
|
||||
AdditionalDependencies=""$(SolutionDir)\$(ConfigurationName)\moses.lib" zlib.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -318,9 +318,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Version="9.00"
|
||||
Name="moses-cmd"
|
||||
ProjectGUID="{5BBAC701-84F5-438E-8F54-B3391F451F2A}"
|
||||
RootNamespace="mosescmd"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
@ -61,11 +62,13 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zlib.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName).exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -86,9 +89,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -137,13 +137,15 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zlib.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName).exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -164,9 +166,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -216,13 +215,15 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/FORCE:MULTIPLE"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zlib.lib dstruct.lib flm.lib lattice.lib misc.lib oolm.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName).exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -243,9 +244,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
@ -297,11 +295,13 @@
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="/FORCE:MULTIPLE"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zlib.lib dstruct.lib flm.lib lattice.lib misc.lib oolm.lib"
|
||||
AdditionalDependencies=""$(SolutionDir)$(ConfigurationName)\moses.lib" zdll.lib"
|
||||
OutputFile="$(OutDir)\$(ProjectName).exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
@ -322,9 +322,6 @@
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual C++ Express 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "moses", "moses\moses.vcproj", "{8122157A-0DE5-44FF-8E5B-024ED6ACE7AF}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "moses-cmd", "moses-cmd\moses-cmd.vcproj", "{5BBAC701-84F5-438E-8F54-B3391F451F2A}"
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Version="9.00"
|
||||
Name="moses"
|
||||
ProjectGUID="{8122157A-0DE5-44FF-8E5B-024ED6ACE7AF}"
|
||||
RootNamespace="moses"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="131072"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
@ -282,18 +283,6 @@
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\AlignmentElement.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AlignmentPair.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AlignmentPhrase.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BitmapContainer.cpp"
|
||||
>
|
||||
@ -354,6 +343,10 @@
|
||||
RelativePath=".\src\GenerationDictionary.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\GlobalLexicalModel.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\hash.cpp"
|
||||
>
|
||||
@ -486,10 +479,6 @@
|
||||
RelativePath=".\src\Manager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\mempool.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\NGramCollection.cpp"
|
||||
>
|
||||
@ -692,18 +681,6 @@
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\AlignmentElement.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AlignmentPair.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AlignmentPhrase.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BitmapContainer.h"
|
||||
>
|
||||
@ -768,6 +745,10 @@
|
||||
RelativePath=".\src\GenerationDictionary.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\GlobalLexicalModel.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\gzfilebuf.h"
|
||||
>
|
||||
@ -852,10 +833,6 @@
|
||||
RelativePath=".\src\Manager.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\mempool.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\NGramCollection.h"
|
||||
>
|
||||
|
@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include "WordsBitmap.h"
|
||||
#include "TypeDef.h"
|
||||
#include "Util.h"
|
||||
#include "mempool.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
@ -21,7 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <list>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
@ -1,492 +0,0 @@
|
||||
/******************************************************************************
|
||||
IrstLM: IRST Language Model Toolkit
|
||||
Copyright (C) 2006 Marcello Federico, ITC-irst Trento, Italy
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
// An efficient memory pool manager
|
||||
// by M. Federico
|
||||
// Copyright Marcello Federico, ITC-irst, 1998
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include "mempool.h"
|
||||
#include "TypeDef.h"
|
||||
#include "Util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*! The pool contains:
|
||||
- entries of size is
|
||||
- tables for bs entries
|
||||
*/
|
||||
|
||||
mempool::mempool(int is, int bs){
|
||||
|
||||
// item size must be multiple of memory alignment step (4 bytes)
|
||||
// example: is is=9 becomes i=12 (9 + 4 - 9 %4 )
|
||||
|
||||
is=(is>(int)sizeof(char *)?is:0);
|
||||
|
||||
is=is + sizeof(char *) - (is % sizeof(char *));
|
||||
|
||||
item_size = is;
|
||||
|
||||
block_size = bs;
|
||||
|
||||
true_size = is * bs;
|
||||
|
||||
block_list = new memnode;
|
||||
|
||||
block_list->block = new char[true_size];
|
||||
|
||||
memset(block_list->block,'0',true_size);
|
||||
|
||||
block_list->next = 0;
|
||||
|
||||
blocknum = 1;
|
||||
|
||||
entries = 0;
|
||||
|
||||
// build free list
|
||||
|
||||
char *ptr = free_list = block_list->block;
|
||||
|
||||
for (int i=0;i<block_size-1;i++) {
|
||||
*(char **)ptr= ptr + item_size;
|
||||
ptr+=item_size;
|
||||
}
|
||||
*(char **)ptr = NULL; //last item
|
||||
|
||||
}
|
||||
|
||||
|
||||
char * mempool::allocate(){
|
||||
|
||||
char *ptr;
|
||||
|
||||
if (free_list==NULL)
|
||||
{
|
||||
memnode *new_block = new memnode;
|
||||
|
||||
new_block->block = new char[true_size];
|
||||
|
||||
//memset(new_block->block,'0',true_size);
|
||||
|
||||
new_block->next = block_list;
|
||||
|
||||
block_list=new_block; // update block list
|
||||
|
||||
/* update free list */
|
||||
|
||||
ptr = free_list = block_list->block;
|
||||
|
||||
for (int i=0;i<block_size-1;i++) {
|
||||
*(char **)ptr = ptr + item_size;
|
||||
ptr = ptr + item_size;
|
||||
}
|
||||
|
||||
*(char **)ptr=NULL;
|
||||
|
||||
blocknum++;
|
||||
}
|
||||
|
||||
assert(free_list);
|
||||
|
||||
ptr = free_list;
|
||||
|
||||
free_list=*(char **)ptr;
|
||||
|
||||
*(char **)ptr=NULL; // reset the released item
|
||||
|
||||
entries++;
|
||||
|
||||
return ptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int mempool::free(char* addr){
|
||||
|
||||
// do not check if it belongs to this pool !!
|
||||
/*
|
||||
memnode *list=block_list;
|
||||
while ((list != NULL) &&
|
||||
((addr < list->block) ||
|
||||
(addr >= (list->block + true_size))))
|
||||
list=list->next;
|
||||
|
||||
if ((list==NULL) || (((addr - list->block) % item_size)!=0))
|
||||
{
|
||||
//TRACE_ERR( "mempool::free-> addr does not belong to this pool\n");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
*(char **)addr=free_list;
|
||||
free_list=addr;
|
||||
|
||||
entries--;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
mempool::~mempool()
|
||||
{
|
||||
memnode *ptr;
|
||||
|
||||
while (block_list !=NULL){
|
||||
ptr=block_list->next;
|
||||
delete [] block_list->block;
|
||||
delete block_list;
|
||||
block_list=ptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void mempool::map (ostream& co){
|
||||
|
||||
co << "mempool memory map:\n";
|
||||
//percorri piu` volte la lista libera
|
||||
|
||||
memnode *bl=block_list;
|
||||
char *fl=free_list;
|
||||
|
||||
char* img=new char[block_size+1];
|
||||
img[block_size]='\0';
|
||||
|
||||
while (bl !=NULL){
|
||||
|
||||
memset(img,'#',block_size);
|
||||
|
||||
fl=free_list;
|
||||
while (fl != NULL){
|
||||
if ((fl >= bl->block)
|
||||
&&
|
||||
(fl < bl->block + true_size))
|
||||
{
|
||||
img[(fl-bl->block)/item_size]='-';
|
||||
}
|
||||
|
||||
fl=*(char **)fl;
|
||||
}
|
||||
|
||||
co << img << "\n";
|
||||
bl=bl->next;
|
||||
}
|
||||
delete [] img;
|
||||
}
|
||||
|
||||
void mempool::stat(){
|
||||
|
||||
TRACE_ERR( "mempool class statistics\n"
|
||||
<< "entries " << entries
|
||||
<< " blocks " << blocknum
|
||||
<< " used memory " << (blocknum * true_size)/1024 << " Kb\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
strstack::strstack(int bs){
|
||||
|
||||
size=bs;
|
||||
list=new memnode;
|
||||
|
||||
list->block=new char[size];
|
||||
|
||||
list->next=0;
|
||||
|
||||
memset(list->block,'\0',size);
|
||||
idx=0;
|
||||
|
||||
waste=0;
|
||||
memory=size;
|
||||
entries=0;
|
||||
blocknum=1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void strstack::stat(){
|
||||
|
||||
TRACE_ERR( "strstack class statistics\n"
|
||||
<< "entries " << entries
|
||||
<< " blocks " << blocknum
|
||||
<< " used memory " << memory/1024 << " Kb\n");
|
||||
}
|
||||
|
||||
|
||||
char *strstack::push(char *s){
|
||||
int len=strlen(s);
|
||||
|
||||
if ((len+1) >= size){
|
||||
TRACE_ERR( "strstack::push string is too long\n");
|
||||
exit(1);
|
||||
};
|
||||
|
||||
if ((idx+len+1) >= size){
|
||||
//append a new block
|
||||
//there must be space to
|
||||
//put the index after
|
||||
//the word
|
||||
|
||||
waste+=size-idx;
|
||||
blocknum++;
|
||||
memory+=size;
|
||||
|
||||
memnode* nd=new memnode;
|
||||
nd->block=new char[size];
|
||||
nd->next=list;
|
||||
|
||||
list=nd;
|
||||
|
||||
memset(list->block,'\0',size);
|
||||
|
||||
idx=0;
|
||||
|
||||
}
|
||||
|
||||
// append in current block
|
||||
|
||||
strcpy(&list->block[idx],s);
|
||||
|
||||
idx+=len+1;
|
||||
|
||||
entries++;
|
||||
|
||||
return &list->block[idx-len-1];
|
||||
|
||||
}
|
||||
|
||||
|
||||
char *strstack::pop(){
|
||||
|
||||
if (list==0) return 0;
|
||||
|
||||
if (idx==0){
|
||||
|
||||
// free this block and go to next
|
||||
|
||||
memnode *ptr=list->next;
|
||||
|
||||
delete [] list->block;
|
||||
delete list;
|
||||
|
||||
list=ptr;
|
||||
|
||||
if (list==0)
|
||||
return 0;
|
||||
else
|
||||
idx=size-1;
|
||||
}
|
||||
|
||||
//go back to first non \0
|
||||
while (idx>0)
|
||||
if (list->block[idx--]!='\0')
|
||||
break;
|
||||
|
||||
//go back to first \0
|
||||
while (idx>0)
|
||||
if (list->block[idx--]=='\0')
|
||||
break;
|
||||
|
||||
entries--;
|
||||
|
||||
if (list->block[idx+1]=='\0')
|
||||
{
|
||||
idx+=2;
|
||||
memset(&list->block[idx],'\0',size-idx);
|
||||
return &list->block[idx];
|
||||
}
|
||||
else{
|
||||
idx=0;
|
||||
memset(&list->block[idx],'\0',size);
|
||||
return &list->block[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *strstack::top(){
|
||||
|
||||
int tidx=idx;
|
||||
memnode *tlist=list;
|
||||
|
||||
if (tlist==0) return 0;
|
||||
|
||||
if (idx==0){
|
||||
|
||||
tlist=tlist->next;
|
||||
|
||||
if (tlist==0) return 0;
|
||||
|
||||
tidx=size-1;
|
||||
}
|
||||
|
||||
//go back to first non \0
|
||||
while (tidx>0)
|
||||
if (tlist->block[tidx--]!='\0')
|
||||
break;
|
||||
|
||||
//aaa\0bbb\0\0\0\0
|
||||
|
||||
//go back to first \0
|
||||
while (tidx>0)
|
||||
if (tlist->block[tidx--]=='\0')
|
||||
break;
|
||||
|
||||
if (tlist->block[tidx+1]=='\0')
|
||||
{
|
||||
tidx+=2;
|
||||
return &tlist->block[tidx];
|
||||
}
|
||||
else{
|
||||
tidx=0;
|
||||
return &tlist->block[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
strstack::~strstack(){
|
||||
memnode *ptr;
|
||||
while (list !=NULL){
|
||||
ptr=list->next;
|
||||
delete [] list->block;
|
||||
delete list;
|
||||
list=ptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
storage::storage(int maxsize,int blocksize)
|
||||
{
|
||||
newmemory=0;
|
||||
newcalls=0;
|
||||
setsize=maxsize;
|
||||
poolsize=blocksize; //in bytes
|
||||
poolset=new mempool* [setsize+1];
|
||||
for (int i=0;i<=setsize;i++)
|
||||
poolset[i]=NULL;
|
||||
}
|
||||
|
||||
|
||||
storage::~storage(){
|
||||
for (int i=0;i<=setsize;i++)
|
||||
if (poolset[i])
|
||||
delete poolset[i];
|
||||
delete [] poolset;
|
||||
}
|
||||
|
||||
char *storage::allocate(int size){
|
||||
|
||||
if (size<=setsize){
|
||||
if (!poolset[size]){
|
||||
poolset[size]=new mempool(size,poolsize/size);
|
||||
}
|
||||
return poolset[size]->allocate();
|
||||
}
|
||||
else{
|
||||
|
||||
newmemory+=size+8;
|
||||
newcalls++;
|
||||
char* p=(char *)calloc(sizeof(char),size);
|
||||
if (p==NULL){
|
||||
TRACE_ERR( "storage::alloc insufficient memory\n");
|
||||
exit(1);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
char *storage::reallocate(char *oldptr,int oldsize,int newsize){
|
||||
|
||||
char *newptr;
|
||||
|
||||
assert(newsize>oldsize);
|
||||
|
||||
if (oldsize<=setsize){
|
||||
if (newsize<=setsize){
|
||||
if (!poolset[newsize])
|
||||
poolset[newsize]=new mempool(newsize,poolsize/newsize);
|
||||
newptr=poolset[newsize]->allocate();
|
||||
memset((char*)newptr,0,newsize);
|
||||
}
|
||||
else
|
||||
newptr=(char *)calloc(sizeof(char),newsize);
|
||||
|
||||
if (oldptr && oldsize){
|
||||
memcpy(newptr,oldptr,oldsize);
|
||||
poolset[oldsize]->free(oldptr);
|
||||
}
|
||||
}
|
||||
else{
|
||||
newptr=(char *)realloc(oldptr,newsize);
|
||||
if (newptr==oldptr){
|
||||
TRACE_ERR( "r\b");
|
||||
}
|
||||
else{
|
||||
TRACE_ERR( "a\b");
|
||||
}
|
||||
}
|
||||
if (newptr==NULL){
|
||||
TRACE_ERR( "storage::realloc insufficient memory\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return newptr;
|
||||
}
|
||||
|
||||
int storage::free(char *addr,int size){
|
||||
|
||||
/*
|
||||
while(size<=setsize){
|
||||
if (poolset[size] && poolset[size]->free(addr))
|
||||
break;
|
||||
size++;
|
||||
}
|
||||
*/
|
||||
|
||||
if (size>setsize)
|
||||
return free(addr),1;
|
||||
else{
|
||||
poolset[size] && poolset[size]->free(addr);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void storage::stat(){
|
||||
int used=0;
|
||||
int memory=sizeof(char *) * setsize;
|
||||
int waste=0;
|
||||
|
||||
for (int i=0;i<=setsize;i++)
|
||||
if (poolset[i]){
|
||||
used++;
|
||||
memory+=poolset[i]->used();
|
||||
waste+=poolset[i]->wasted();
|
||||
}
|
||||
|
||||
TRACE_ERR( "storage class statistics\n"
|
||||
<< "alloc entries " << newcalls
|
||||
<< " used memory " << newmemory/1024 << "Kb\n"
|
||||
<< "mpools " << setsize
|
||||
<< " active " << used
|
||||
<< " used memory " << memory/1024 << "Kb"
|
||||
<< " wasted " << waste/1024 << "Kb\n");
|
||||
}
|
@ -1,166 +0,0 @@
|
||||
/******************************************************************************
|
||||
IrstLM: IRST Language Model Toolkit
|
||||
Copyright (C) 2006 Marcello Federico, ITC-irst Trento, Italy
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
// An efficient memory manager
|
||||
// by M. Federico
|
||||
// Copyright Marcello Federico, ITC-irst, 1998
|
||||
|
||||
#ifndef MF_MEMPOOL_H
|
||||
#define MF_MEMPOOL_H
|
||||
|
||||
#ifndef NULL
|
||||
const int NULL=0;
|
||||
#endif
|
||||
|
||||
#include <iostream> // std::ostream
|
||||
|
||||
//! Memory block
|
||||
/*! This can be used by:
|
||||
- mempool to store items of fixed size
|
||||
- strstack to store strings of variable size
|
||||
*/
|
||||
|
||||
class memnode{
|
||||
friend class mempool; //!< grant access
|
||||
friend class strstack; //!< grant access
|
||||
char *block; //!< block of memory
|
||||
memnode *next; //!< next block ptr
|
||||
};
|
||||
|
||||
|
||||
//! Memory pool
|
||||
|
||||
/*! A memory pool is composed of:
|
||||
- a linked list of blocknum memory blocks
|
||||
- each block might contain up to block_size items
|
||||
- each item is made of exactly item_size bytes
|
||||
*/
|
||||
|
||||
class mempool{
|
||||
int block_size; //!< number of entries per block
|
||||
int item_size; //!< number of bytes per entry
|
||||
int true_size; //!< number of bytes per block
|
||||
memnode* block_list; //!< list of blocks
|
||||
char* free_list; //!< free entry list
|
||||
int entries; //!< number of stored entries
|
||||
int blocknum; //!< number of allocated blocks
|
||||
public:
|
||||
|
||||
//! Creates a memory pool
|
||||
mempool(int is, int bs);
|
||||
|
||||
//! Destroys memory pool
|
||||
~mempool();
|
||||
|
||||
//! Prints a map of memory occupancy
|
||||
void map(std::ostream& co);
|
||||
|
||||
//! Allocates a single memory entry
|
||||
char *allocate();
|
||||
|
||||
//! Frees a single memory entry
|
||||
int free(char* addr);
|
||||
|
||||
//! Prints statistics about this mempool
|
||||
void stat();
|
||||
|
||||
//! Returns effectively used memory (bytes)
|
||||
/*! includes 8 bytes required by each call of new */
|
||||
|
||||
int used(){return blocknum * (true_size + 8);};
|
||||
|
||||
//! Returns amount of wasted memory (bytes)
|
||||
int wasted(){return used()-(entries * item_size);};
|
||||
};
|
||||
|
||||
//! A stack to store strings
|
||||
|
||||
/*!
|
||||
The stack is composed of
|
||||
- a list of blocks memnode of fixed size
|
||||
- attribute blocknum tells the block on top
|
||||
- attribute idx tells position of the top string
|
||||
*/
|
||||
|
||||
class strstack{
|
||||
memnode* list; //!< list of memory blocks
|
||||
int size; //!< size of each block
|
||||
int idx; //!< index of last stored string
|
||||
int waste; //!< current waste of memory
|
||||
int memory; //!< current use of memory
|
||||
int entries; //!< current number of stored strings
|
||||
int blocknum; //!< current number of used blocks
|
||||
|
||||
public:
|
||||
|
||||
strstack(int bs=1000);
|
||||
|
||||
~strstack();
|
||||
|
||||
char *push(char *s);
|
||||
|
||||
char *pop();
|
||||
|
||||
char *top();
|
||||
|
||||
void stat();
|
||||
|
||||
int used(){return memory;}
|
||||
|
||||
int wasted(){return waste;}
|
||||
};
|
||||
|
||||
//! Manage multiple memory pools
|
||||
|
||||
/*!
|
||||
This class permits to manage memory pools
|
||||
with items up to a specified size.
|
||||
- items within the allowed range are stored in memory pools
|
||||
- items larger than the limit are allocated with new
|
||||
*/
|
||||
|
||||
class storage{
|
||||
mempool **poolset; //!< array of memory pools
|
||||
int setsize; //!< number of memory pools/maximum elem size
|
||||
int poolsize; //!< size of each block
|
||||
int newmemory; //!< stores amount of used memory
|
||||
int newcalls; //!< stores number of allocated blocks
|
||||
public:
|
||||
|
||||
//! Creates storage
|
||||
storage(int maxsize,int blocksize);
|
||||
|
||||
//! Destroys storage
|
||||
~storage();
|
||||
|
||||
//! Allocates memory
|
||||
char *allocate(int size);
|
||||
|
||||
//! Realloc memory
|
||||
char *reallocate(char *oldptr,int oldsize,int newsize);
|
||||
|
||||
//! Frees memory of an entry
|
||||
int free(char *addr,int size=0);
|
||||
|
||||
//! Prints statistics about storage
|
||||
void stat();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user