From c4dff160450607371d7e13def07bfa1fae2b8c56 Mon Sep 17 00:00:00 2001 From: Trygve Date: Tue, 27 Feb 2024 18:53:12 +0100 Subject: [PATCH] =?UTF-8?q?Starta=20p=C3=A5=2012?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab_2/12/Makefile | 18 ++++++++++++++++++ lab_2/12/chain-random-walk.o | Bin 0 -> 9400 bytes lab_2/12/memleak.cpp | 4 ++++ 3 files changed, 22 insertions(+) create mode 100644 lab_2/12/Makefile create mode 100644 lab_2/12/chain-random-walk.o diff --git a/lab_2/12/Makefile b/lab_2/12/Makefile new file mode 100644 index 0000000..0ef13b8 --- /dev/null +++ b/lab_2/12/Makefile @@ -0,0 +1,18 @@ +binary = memleak +folder = memleak +objects = $(patsubst %.cpp,%.o,$(wildcard *.cpp)) + +run: $(binary) + ./$(binary) 7 100000000 + +$(binary): $(objects) + g++ -o $@ $^ + +clean: + rm -f *.o + +clear: clean + rm -f *.zip $(binary) + +zip: clean + zip $(folder) Makefile *.cpp *.h diff --git a/lab_2/12/chain-random-walk.o b/lab_2/12/chain-random-walk.o new file mode 100644 index 0000000000000000000000000000000000000000..5c67061d37b9622d9357592210bb472a9e89598e GIT binary patch literal 9400 zcmbtZeQXrR6`%7Fz(8^)CDci1at4;iQ7GyTly8)Z>umJu(n9&1k+a{H*C*Pk5w2!%H%z!`4 z6cU(1FH_RXTO%X;C;_XKP$S40!dt4%f>`NBW`vEL9t4$Kv5`#hLvuQ>f( zcP_R=n+>cRJFvoCK!w8!G!=Nh@A~!Ys93xjXxC<~G{Uef>R?&OX6VEFCiPQafEdvI z`nM-DEA(UYUdOiRx%0BPdTvb5y{{kJa(((P319;u)(U+Hsx)+Fo_;hxFsHM#_9B&(Hs zZxqX|YJJ9X@t&Uhi$vZYO$UNhT-)`$4Qv7<(@3Hx>-GF~u@jJMF#Xf0Z1z;a3ejVpWZTqu| zk6UOdzHK&tg({jC{~^Uc&h;yDCI9V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Ea9ZPhKBPA1{o zMTAmmGZunBm(^#@Nc3rS-<|3U^=8t&v5Yw&tN>y?Mpq`1jEPWpCf(Odi{bwm-+=zx zU*oo+W;LZXT?6;{e9|*SqnEz!qL2Fr>Cxz=zsp4*_Y=~i(Mx}?(x>lyj34(A(xcH! zztcq@_bt++(Mz9t!~NraMS3)P=^t|OkLNOkR+%79|4M(Q~ysY{u}8()A*QpWso|8n|Y2FbhS|9j=XPU+KtvYY|{xcUFBOa8cj zIsG?!_@7k%Y5yXhPXCX1=wG@?ef%E<+H}_SibwtwKgH9j^cx6JW3>`o=fKey5{*fv zZ=v?@Hm4)SB0Z8E1OP*I#;+@VXIxIRFDw5}{eC4_a5!}8)bn0e!tpyUU4uT>Bv37A%g0n3SU-0Cmafn GTk&7_TmjDj literal 0 HcmV?d00001 diff --git a/lab_2/12/memleak.cpp b/lab_2/12/memleak.cpp index 89b57b9..5833225 100644 --- a/lab_2/12/memleak.cpp +++ b/lab_2/12/memleak.cpp @@ -45,7 +45,11 @@ int main(int argc, char** argv) /* here we are calling the random walk step; * this returns a new configuration (float array) on the heap */ + + // Simple fix to memleak: + float* old_configuration = present_configuration; present_configuration = crw::step(size, present_configuration); + delete old_configuration; float present_elongation = crw::elongation(size, present_configuration); if(present_elongation > extreme_elongation)