diff --git "a/Dokument\303\241ci\303\263.odt" "b/Dokument\303\241ci\303\263.odt" index ae55bac7d3e123cf0adfb06378c6ba97bb305546..f3dc3da47a8c547e154ca328017486e2c91785c8 100644 Binary files "a/Dokument\303\241ci\303\263.odt" and "b/Dokument\303\241ci\303\263.odt" differ diff --git a/NHF/include/heap.h b/NHF/include/heap.h index 1b385985a9774d458263016669389afd83ba65db..4f17217cdae62f6c25edf2708af1271a9e4e166a 100644 --- a/NHF/include/heap.h +++ b/NHF/include/heap.h @@ -60,8 +60,9 @@ class heap void free(const memnum pid); /** \brief 10%-onként átlagolja a memória telítettségét, - * és kirajzolja egy diagrammon. Ha az adott 10% több mint fele + * és kirajzolja egy diagrammon. Ha az adott 10% több mint fele (>50%) * telített, akkor az a 10% telítettnek tekinthető. + * Ha a memória kisebb, mint 10 blokk, const char* hibát dob. * Formátum: #------# |......|//telítetlen @@ -78,7 +79,7 @@ class heap * \param os std::ostream& * \param mem const heap& A kiírandó memória referenciája - * \return friend std::ostream& A sorbafűzhetőség miatt + * \return std::ostream& A sorbafűzhetőség miatt * */ friend std::ostream& operator<<(std::ostream& os,const heap& mem); diff --git a/NHF/include/proc_test.h b/NHF/include/proc_test.h index 690816cef5e98233e88a73a07df2a1713765a1df..4090590c9a1ee24b359ec849bd0a1945acdafd32 100644 --- a/NHF/include/proc_test.h +++ b/NHF/include/proc_test.h @@ -22,7 +22,8 @@ class proc_test : public process */ proc_test(const std::string name, process proc, memnum block_size):process(proc),name(name),next(NULL) { - this->init(block_size); + init(block_size); + next=NULL; } std::string get_name() { return name; } proc_test* get_next() { return next; } diff --git a/NHF/include/process.h b/NHF/include/process.h index b4032a7b3bcdcdee04fefbdf005bd06e12c7b936..4c529e38037979cbaf3567e861dc583b844eb1f4 100644 --- a/NHF/include/process.h +++ b/NHF/include/process.h @@ -1,6 +1,8 @@ #ifndef PROCESS_H #define PROCESS_H +#include<iostream> + #include "heap.h" /** \brief Egy process, mely tud magának kérni memóriaterületet @@ -8,10 +10,9 @@ class process { public: - /** \brief A paraméterként kapott méretű blokkot kérvényez a memórától - * a heap::allocate() függvényen keresztül. + /** \brief Létrehoz egy processt az foglalt terület nélkül, + * beállítja, hogy melyik memóriába fog kerülni. * - * \param block_size A processznek szükséges memória. * \param mem heap& A paraméterként kapott memória referenciája. * Erre szükség van, különben a processz a későbbiekben nem fogja tuni, hogy * melyik memóriában van, így nem tudja felszabadítási kérvényét jelezni. @@ -19,22 +20,48 @@ class process */ process(heap& mem):mem(mem){} -// process(process& other):mem(this->mem){pid=this->pid;} - - /** \brief A heap::free() függvényen keresztül jelzi a memória felé, - * hogy nincs már szüksége a foglalt blokkra. + /** \brief A paraméterként kapott méretű blokkot kérvényez a memórától + * a heap::allocate() függvényen keresztül. + * Explicit módon hívandó. * - * \param false + * \param block_size memnum A processznek szükséges memória. + * \return void * */ -// ~process(){mem.free(pid);} void init(memnum block_size) { - pid=mem.allocate(block_size); + //hibakezelést még csiszolni kell + try{ + pid=mem.allocate(block_size); + } + catch(std::domain_error err) + { + std::cout<<err.what()<<std::endl; + } } + + /** \brief A heap::free() függvényen keresztül jelzi a memória felé, + * hogy nincs már szüksége a foglalt blokkra. + * Explicit módon hívandó. + * + * \return void + * + */ void kill() { - mem.free(pid); + //a hibakezelést még csiszolni kell + try + { + mem.free(pid); + } + catch(invalid_pid err) + { + std::cout<<err.what()<<std::endl; + } + catch(std::out_of_range err) + { + std::cout<<err.what()<<std::endl; + } } protected: memnum pid;/**< A process pid-ja */ diff --git a/NHF/include/test_container.h b/NHF/include/test_container.h index 4c40cd21435dbba5c1df2dbc23b45924e03e4714..2f9c0ec136fea7d34b3dbbd344d73561b2988eb8 100644 --- a/NHF/include/test_container.h +++ b/NHF/include/test_container.h @@ -1,6 +1,8 @@ #ifndef TEST_CONTAINER_H #define TEST_CONTAINER_H +#include<stdexcept> + #include "proc_test.h" @@ -19,8 +21,9 @@ class test_container * */ void add(proc_test* proc); - //hibát lehet kezelni, amikor a név nincs benne, vagy üres az egész, ilyesmi + /** \brief Kitörli a megadott nevű process-t a listából. + * Érvénytelen processnév esetén std::invalid_argument hibát dob. * * \param name const std::string A kiirtandó process neve * \return void diff --git a/NHF/main.cpp b/NHF/main.cpp index b4637d3cdb952aae8768bec80bf81d49869c47e4..2e3df0f349283c7ee542886ae523767801c02b75 100644 --- a/NHF/main.cpp +++ b/NHF/main.cpp @@ -9,10 +9,24 @@ int main() { heap mem(100); test_container c; - c.add(new proc_test("pidgin",process(mem),20)); - c.add(new proc_test("libpurple",process(mem),10)); - c.add(new proc_test("finch",process(mem),20)); - c.kill("libpurple"); - cout<<mem<<endl; + try + { + c.add(new proc_test("linux",process(mem),95)); + /* + c.add(new proc_test("pidgin",process(mem),20)); + c.add(new proc_test("libpurple",process(mem),10)); + c.add(new proc_test("finch",process(mem),20)); + c.kill("libpurple");*/ + cout<<mem<<endl; + } + catch(invalid_argument err) + { + cout<<err.what()<<endl; + } + catch(const char* err) + { + cout<<err<<endl; + } + return 0; } diff --git a/NHF/src/heap.cpp b/NHF/src/heap.cpp index 0cf368df5fa1ea0e9f68cf4e9f7f383ce0cc54b7..a7aa1995fc89a95f463a5afddd0b7ed57b3a15d2 100644 --- a/NHF/src/heap.cpp +++ b/NHF/src/heap.cpp @@ -107,19 +107,19 @@ std::ostream& operator<<(std::ostream& os,const heap& mem) return os; } #else -std::ostream& operator<<(std::ostream& os,const heap& mem)//nem biztos, hogy jó ötlet az, ha kaszkádosítható +std::ostream& operator<<(std::ostream& os,const heap& mem) { + //nem biztos, hogy jó ötlet az, ha kaszkádosítható if(mem.size<10) - throw "A memória túl kicsit, nem kiírható."; + throw ("A memória túl kicsi, nem kiírható."); const char mem_end[]="#------#", filled_unit[]="======", empty_unit[]="......", border='|'; os<<mem_end<<std::endl; memnum unit_size=mem.size/10; - //A févég fennmaradó rész mindig legfeljebb 10 byte, így elhanyagolható. - //A ciklus második kilépési feltétele felelős az elhanyagolásért. - for(memnum i=0; i<mem.size && i+unit_size<=mem.size; i+=unit_size)//itt még van egy kis hiba!? + //A kilépési feltétel miatt a végén fennmaradó rész mindig legfeljebb 10 blokk, így elhanyagolható. + for(memnum i=0; i<mem.size-(mem.size%10) /*&& i+unit_size<=mem.size*/; i+=unit_size) { const char *content=NULL; memnum filled=0; diff --git a/NHF/src/test_container.cpp b/NHF/src/test_container.cpp index 77a17f9de74fc778803581cbfab13e8ca54d8928..2dd9aec29c36036e0f5f3f8190820977d3aea3d3 100644 --- a/NHF/src/test_container.cpp +++ b/NHF/src/test_container.cpp @@ -10,19 +10,13 @@ void test_container::kill(std::string name) list_head=list_head->next; delete k; return; - }/* - else if(list_head->get_next()!=NULL && list_head->get_next()->get_name()==name) - { - k=list_head->next; - list_head->next=k->next; - delete k; - return; - }*/ + } for(i=list_head; i->get_next()!=NULL && i->get_next()->get_name()!=name; i=i->get_next()){} - //i a törlendő elem előtt áll + //i a törlendő elem előtt áll, vagy nincs ilyen nevű process k=i->next; + if(k==NULL) + throw (std::invalid_argument("Érvénytelen processnév")); i->next=k->next; -// k->kill(); delete k; } @@ -32,23 +26,13 @@ test_container::~test_container() { kill(list_head->get_name()); } -/* - //az iterálást a végén még tesztelni kell - for(proc_test *i=list_head, *j=i->get_next(); - i!=NULL; - i=j, j=j->get_next() ) - { - delete i; - } -*/ } void test_container::add(proc_test* proc) { if(list_head==NULL) { - list_head=proc;//remélhetőleg az implicit másoló konstruktor hívódik - //mivel a proc_test konstruktora NULL-ra éllítja a next-et, itt az implicit másoló pont megfelel + list_head=proc; return; } proc_test *i; diff --git a/diagram.uxf b/diagram.uxf index 99e4c7fd5a99f65fd3b58aa9e967c818ba2ba4f8..34c79e558474e8a7ea21586388a3698cfaf4cb92 100644 --- a/diagram.uxf +++ b/diagram.uxf @@ -4,9 +4,9 @@ <type>com.umlet.element.Class</type> <coordinates> <x>430</x> - <y>80</y> - <w>200</w> - <h>80</h> + <y>50</y> + <w>250</w> + <h>110</h> </coordinates> <panel_attributes><<mem_block>> -- @@ -14,6 +14,8 @@ + block_size: unsigned int //+ byte: char + filled: bool ++ set(bool,unsigned int): void ++ reset(): void fg=blue</panel_attributes> <additional_attributes/> </element> @@ -68,10 +70,9 @@ fg=blue</panel_attributes> # pid: const unsigned int mem: heap& -- -/+ process(block_size: unsigned int,/ -/ mem: heap&)/ -/+ ~process()/ -//destruktorban ki kell adni egy free-t a heap-nek +/+ process(mem: heap&)/ +init(block_size: unsigned int):void +kill():void fg=blue</panel_attributes> <additional_attributes/> </element>