Login
Username:

Password:

Remember me



Lost Password?

Register now!
Sections
Who's Online
54 user(s) are online (38 user(s) are browsing Forums)

Members: 0
Guests: 54

more...
Support us!
Recent OS4 Files
OS4Depot.net





AllocVec vs AllocMem
Just popping in
Joined:
1/20 18:06
From SF Bay Area, California
Posts: 6
An Amiga memory allocation n00b question for you:

Apart from AllocVec() requiring v2, is there any reason to prefer AllocMem() over AllocVec() given that AllocVec() stores the size in the allocator?

   Report Go to top

Re: AllocVec vs AllocMem
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 2703
@remotenemesis

You should be using AllocVecTags() for AmigaOS4.0 and newer, the older AllocVec() / AllocMem() don't have proper flags, for the new memory system.

(Should the memory be swappable, should the memory be executable and so on, memory alignment, should memory not be shared, should memory cleared.)

AllocMem() does not keep track of amount of memory you have allocated, so when you Free the memory you need keep that recorded, somewhere else. So here is postnasal of keep the wrong size somewhere, free the wrong number of block, resulting memory leeks or total failure, freeing blocks you should not have.

In most cases you might want to just use malloc() and free(), in clib, this work on all operating systems, unless you need a particular feature.

Small coding tip for new beginners:

Do not put all variable declaration of top functions, this common mistake.
Variable declaration are initialized very time function is called, if the variable are not used, because of an "if" statement, then setting up that variable was not necessary.


Edited by LiveForIt on 2018/5/10 10:10:26
Edited by LiveForIt on 2018/5/10 10:12:52
Edited by LiveForIt on 2018/5/10 10:18:38
Edited by LiveForIt on 2018/5/10 10:21:05
_________________
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
   Report Go to top

Re: AllocVec vs AllocMem
Just can't stay away
Joined:
2008/1/6 17:56
From Pennsylvania, USA
Posts: 1279
@LiveForIt
Good info but this is the "Amiga Classic" forum and I don't think AllocVecTags() applies to classic Amiga programming.

_________________
Amiga X1000 with 2GB memory & OS 4.1FE + Radeon HD 5450

   Report Go to top

Re: AllocVec vs AllocMem
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 2703
@xenic

Well if you making program now days you should make your programs cross platform. He should be doing something like.
This is classic forum on Next Generation site.

#ifdef amigaos4
#define my_alloc(x) AllocVecTags(...)
#else
#define my_alloc(x) AllocVec(...)
#endif

but as I say it best to use malloc() and free() command, they are also pooled, and they are cross platform.

Best Regards
LiveForIt


_________________
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
   Report Go to top

Re: AllocVec vs AllocMem
Just can't stay away
Joined:
2007/1/26 21:48
From New Zealand
Posts: 1948
@remotenemesis

Quote:
Apart from AllocVec() requiring v2, is there any reason to prefer AllocMem() over AllocVec() given that AllocVec() stores the size in the allocator?

Simple answer: no. Always use AllocVec(). I can't think of any reason why you'd want to use AllocMem() and have to store the allocation size manually.

Hans

_________________
http://hdrlab.org.nz/ - Amiga OS 4 projects, programming articles and more.
https://keasigmadelta.com/ - more of my work
   Report Go to top

Re: AllocVec vs AllocMem
Just popping in
Joined:
1/20 18:06
From SF Bay Area, California
Posts: 6
@LiveForIt @Hans

Thanks for the good info. I'm actually coding on AROS right but now looking to support OS4 as well once I get my hands on some suitable hardware.

   Report Go to top

Re: AllocVec vs AllocMem
Not too shy to talk
Joined:
2008/5/2 12:14
From Sweden
Posts: 486
@remotenemesis & Hans

I always use AllocMem for objects of known size, since the object knows its size itself, no need for AllocVec to store it too, wasting 4 bytes on each allocation.

Specifically on linked lists with many, possibly thousands of allocation you save these 4 bytes each time.

Else, especially for large random size allocations, use AllocVec to save yourself knowing the size of the allocation, as Hans said.

_________________
Software developer for Amiga OS3 and OS4.
Develops for OnyxSoft and the Amiga using E and C and occasionally C++
   Report Go to top

Re: AllocVec vs AllocMem
Just popping in
Joined:
2015/6/11 8:51
From Cologne
Posts: 121
@Deniil
On current AmigaOS4 AllocMem uses AllocVecTags internally. So at least here you actually save exactly 0 bytes by using AllocMem.

   Report Go to top

Re: AllocVec vs AllocMem
Home away from home
Joined:
2006/11/20 16:26
From Norway
Posts: 2703
@Deniil

Yes but is there not fix block size something like 512 bytes or 1024 bytes or something like that, if so you will not actually save 4 bytes.


Edited by LiveForIt on 2018/5/14 16:51:43
_________________
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
   Report Go to top

Re: AllocVec vs AllocMem
Quite a regular
Joined:
2006/12/2 0:35
From Sydney
Posts: 665
@Deniil

As Daytona said, all the old Exec calls like AllocMem(), AllocPort(), etc, call the new code AllocVecTags(), AllocSysObjectTags (ASOT_PORT), etc.
Using the old calls slows down the system and saves nothing. Same with all the old DOS calls - they only emulate the new calls and thus are less efficient.

_________________
cheers
tony
   Report Go to top





[Advanced Search]


Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project