Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
36 user(s) are online (20 user(s) are browsing Forums)

Members: 2
Guests: 34

DJBase, Arthas, more...

Headlines

 
  Register To Post

AllocVec vs AllocMem
Just popping in
Just popping in


See User information
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?

Go to top
Re: AllocVec vs AllocMem
Home away from home
Home away from home


See User information
@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 11:10:26
Edited by LiveForIt on 2018/5/10 11:12:52
Edited by LiveForIt on 2018/5/10 11:18:38
Edited by LiveForIt on 2018/5/10 11:21:05
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: AllocVec vs AllocMem
Just can't stay away
Just can't stay away


See User information
@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

Go to top
Re: AllocVec vs AllocMem
Home away from home
Home away from home


See User information
@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.
Go to top
Re: AllocVec vs AllocMem
Home away from home
Home away from home


See User information
@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
Go to top
Re: AllocVec vs AllocMem
Just popping in
Just popping in


See User information
@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.

Go to top
Re: AllocVec vs AllocMem
Quite a regular
Quite a regular


See User information
@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++
Go to top
Re: AllocVec vs AllocMem
Not too shy to talk
Not too shy to talk


See User information
@Deniil
On current AmigaOS4 AllocMem uses AllocVecTags internally. So at least here you actually save exactly 0 bytes by using AllocMem.

Go to top
Re: AllocVec vs AllocMem
Home away from home
Home away from home


See User information
@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 17:51:43
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: AllocVec vs AllocMem
Quite a regular
Quite a regular


See User information
@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
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project