Skip to content

Commit

Permalink
init : 初始化程序结构、多文件架构
Browse files Browse the repository at this point in the history
add : 内存总容量以及分配方法输入
config : 头部以及交互部分格式化输出
  • Loading branch information
D0ub1ePieR committed Jun 22, 2018
1 parent 1292a18 commit 7cfffc4
Show file tree
Hide file tree
Showing 27 changed files with 372 additions and 0 deletions.
Binary file added MemoryAllocate/.vs/MemoryAllocate/v14/.suo
Binary file not shown.
Binary file added MemoryAllocate/MemoryAllocate.VC.db
Binary file not shown.
28 changes: 28 additions & 0 deletions MemoryAllocate/MemoryAllocate.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MemoryAllocate", "MemoryAllocate\MemoryAllocate.vcxproj", "{8238E100-982E-4B36-90E1-025BB1A9B7A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8238E100-982E-4B36-90E1-025BB1A9B7A6}.Debug|x64.ActiveCfg = Debug|x64
{8238E100-982E-4B36-90E1-025BB1A9B7A6}.Debug|x64.Build.0 = Debug|x64
{8238E100-982E-4B36-90E1-025BB1A9B7A6}.Debug|x86.ActiveCfg = Debug|Win32
{8238E100-982E-4B36-90E1-025BB1A9B7A6}.Debug|x86.Build.0 = Debug|Win32
{8238E100-982E-4B36-90E1-025BB1A9B7A6}.Release|x64.ActiveCfg = Release|x64
{8238E100-982E-4B36-90E1-025BB1A9B7A6}.Release|x64.Build.0 = Release|x64
{8238E100-982E-4B36-90E1-025BB1A9B7A6}.Release|x86.ActiveCfg = Release|Win32
{8238E100-982E-4B36-90E1-025BB1A9B7A6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
161 changes: 161 additions & 0 deletions MemoryAllocate/MemoryAllocate/MemoryAllocate.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8238E100-982E-4B36-90E1-025BB1A9B7A6}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MemoryAllocate</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="first_fit.cpp" />
<ClCompile Include="global.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="first_fit.h" />
<ClInclude Include="global.h" />
<ClInclude Include="include.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
39 changes: 39 additions & 0 deletions MemoryAllocate/MemoryAllocate/MemoryAllocate.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="global.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="first_fit.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="first_fit.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="global.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="include.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
11 changes: 11 additions & 0 deletions MemoryAllocate/MemoryAllocate/first_fit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include"first_fit.h"

void init_ff(int total)
{
cout << "init success" << total << endl;
}

int first_fit(int number, int size)
{
return 0;
}
4 changes: 4 additions & 0 deletions MemoryAllocate/MemoryAllocate/first_fit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "global.h"

void init_ff(int total);
int first_fit(int number, int size);
78 changes: 78 additions & 0 deletions MemoryAllocate/MemoryAllocate/global.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "global.h"

//获取内存总大小
int get_total_memory()
{
string tmp;
int i, flag = 0;
while (1)
{
//system("cls");
flag = 0;
cout << "---------------------------------------------------------------------" << endl;
cout << " 请输入总内存大小:";
cin >> tmp;
//校验输入值是否合法
for (i = 0; i < tmp.length(); i++)
if (!isdigit(tmp[i]))
flag = 1;
if (!flag)
break;
else
{
cout << " 请输入正确的数值!" << endl;
cout << "---------------------------------------------------------------------" << endl;
}
}
return atoi(tmp.c_str());
}

void print_head(int total, int method)
{
string str;
switch (method)
{
//设置分配方法名称
case 1:str = "FF"; break;
case 2:str = "NF"; break;
case 3:str = "BF"; break;
case 4:str = "WF"; break;
};
printf(" *************************\n");
printf(" * total memory:%5dM *\n", total);
if (method)
cout << " * allocate method:" << str << " *" << endl;
printf(" *************************\n");
}

//获取分配方法
int get_command()
{
string tmp;
while (1)
{
cout << " ---------------------------------------------------------------------" << endl;
cout << " | 请选择动态内存分配方法 |" << endl;
cout << " | 1.首次适应算法 |" << endl;
cout << " | 2.循环首次适应算法 |" << endl;
cout << " | 3.最佳适应算法 |" << endl;
cout << " | 4.最坏适应算法 |" << endl;
cout << " ---------------------------------------------------------------------" << endl;
cout << " 请输入你的选择:";
cin >> tmp;
//校验输入合法性
if (tmp.length() == 1 && tmp[0] <= '4' && tmp[0] >= '1')
break;
else
cout << ">>>>>请输入正确的选择!" << endl;
}
return atoi(tmp.c_str());
}

//初始化函数数组
void init(int(*alloc[])(int, int), void(*init_func[])(int))
{
alloc[1] = first_fit;

init_func[1] = init_ff;
}
16 changes: 16 additions & 0 deletions MemoryAllocate/MemoryAllocate/global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include "include.h"

static int total_mem, command;

static int(*allocat_function[5])(int number, int size); //分配方法处理函数
static void(*init_function[5])(int total); //初始化分配链表

//获取总内存大小
int get_total_memory();
//标准化输出界面顶部
void print_head(int total, int method);
//获取分配方式
int get_command();
//初始化各函数数组
void init(int(*alloc[])(int, int), void(*init_func[])(int));
7 changes: 7 additions & 0 deletions MemoryAllocate/MemoryAllocate/include.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

#include "first_fit.h"
20 changes: 20 additions & 0 deletions MemoryAllocate/MemoryAllocate/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "global.h"

int main()
{
init(allocat_function,init_function); //初始化

//获取总内存值
total_mem=get_total_memory();
system("cls");
print_head(total_mem, 0);

//获取分配方法
command = get_command();
system("cls");
print_head(total_mem, command);

//初始化链表
init_function[command](total_mem);

}
6 changes: 6 additions & 0 deletions MemoryAllocate/MemoryAllocate/x64/Debug/MemoryAllocate.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
 main.cpp
global.cpp
first_fit.cpp
正在生成代码...
MemoryAllocate.vcxproj -> C:\Users\Administrator\Desktop\Dynamic-memory-allocation\MemoryAllocate\x64\Debug\MemoryAllocate.exe
MemoryAllocate.vcxproj -> C:\Users\Administrator\Desktop\Dynamic-memory-allocation\MemoryAllocate\x64\Debug\MemoryAllocate.pdb (Full PDB)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=8.1
Debug|x64|C:\Users\Administrator\Desktop\Dynamic-memory-allocation\MemoryAllocate\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added MemoryAllocate/MemoryAllocate/x64/Debug/main.obj
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added MemoryAllocate/x64/Debug/MemoryAllocate.exe
Binary file not shown.
Binary file added MemoryAllocate/x64/Debug/MemoryAllocate.ilk
Binary file not shown.
Binary file added MemoryAllocate/x64/Debug/MemoryAllocate.pdb
Binary file not shown.

0 comments on commit 7cfffc4

Please sign in to comment.