WEBVTT

00:00.590 --> 00:08.710
Structures work exactly the same as any other data type when it comes to using them with functions.

00:08.720 --> 00:18.440
So here this example we have our book that we defined last time and we're passing a book type by value

00:18.470 --> 00:25.570
to this function func and doesn't do anything it's really just for illustration.

00:25.670 --> 00:32.980
But I would run this and show you the size of a book versus the size of an integer.

00:32.990 --> 00:36.970
So it's see this venture is four bytes.

00:36.980 --> 00:42.070
We saw this in the second section.

00:42.320 --> 00:49.630
And the size of the book type is 524 bytes OK.

00:49.660 --> 00:57.380
It's it's quite a bit bigger than just a simple integer now and doing copy's which is what we would

00:57.380 --> 01:09.620
do here we're passing a copy of a book to func and doing copies of bigger types that we make are usually

01:09.680 --> 01:17.900
a bad idea because it not only takes more space but but it's also slower because you're copying lots

01:17.900 --> 01:19.150
of data.

01:19.370 --> 01:28.050
And in fact in our case here this book type the copy wouldn't even work properly since there's now there's

01:28.170 --> 01:33.470
no there's no way you can copy an array without using something like Sturr copy.

01:33.690 --> 01:38.360
OK so we don't actually get a real proper copy for our book.

01:39.260 --> 01:39.850
OK.

01:40.080 --> 01:48.000
So instead of doing what I did here what I typically do is pass trucks by reference.

01:48.040 --> 01:51.570
OK so I'll do actually something more like this.

01:55.190 --> 01:55.850
OK.

01:55.970 --> 02:02.870
That way we're only passing the address of the struct which is much faster and smaller in terms of memory

02:03.740 --> 02:12.060
footprint because now an address is probably only about 8 bytes or 4 bytes it depends on your system.

02:13.040 --> 02:20.990
And if I don't want my functions to be able to change destructs I will pass them by constant reference

02:21.370 --> 02:23.040
to something like this.

02:23.690 --> 02:28.720
So that if I just want to look at the type K for I want to change a tire.

02:28.730 --> 02:30.880
I wouldn't use Konst.

02:30.940 --> 02:42.330
So with our Strax our own user defined types we will be passing them by reference or possibly by pointer

02:42.340 --> 02:44.330
depends on the situation.

02:44.370 --> 02:54.790
OK so that's the convention we'll be using when passing struts to functions and we'll look at structures

02:54.790 --> 02:56.840
with pointers in the next lecture.
