[wdmaudiodev] Re: How to allocate memory aligned to some specific value...

  • From: "Nitin Porwal, Noida" <nitinp@xxxxxxxxxxxxxxxxx>
  • To: wdmaudiodev@xxxxxxxxxxxxx
  • Date: Fri, 9 Jan 2004 15:13:54 +0530

Hi,
        Thanks for your reply. I knew this solution, is this the only way to
get the aligned memory. Because there is a huge wastage of memory in this
approach. I want to align some of the memory in my driver to 2KB. in that
case the wastage of memory will be so huge.
        If anybody know any other solution to this problem please let me
know...

Thanks
Nitin

-----Original Message-----
From: wdmaudiodev-bounce@xxxxxxxxxxxxx
[mailto:wdmaudiodev-bounce@xxxxxxxxxxxxx]On Behalf Of Sam Tertzakian
Sent: Friday, January 09, 2004 1:35 PM
To: wdmaudiodev@xxxxxxxxxxxxx
Subject: [wdmaudiodev] Re: How to allocate memory aligned to some specific
value...


Can you do something like this:

actual_ptr = alloc( desired_amt + desired_alignment );
work_ptr = actual_ptr - ( actual_ptr % desired_alignment ) + 
desired_alignment;
// work_ptr is aligned now to desired alignment

...now use work_ptr...

then,

free( actual_ptr )  // not work_ptr...need to keep actual_ptr until free

example:

i want 100 bytes aligned on 64-byte boundry (all numbers decimal)

actual_ptr = alloc( 100 + 64 );    //os returns 1324
// 1324 % 64 = 44...
work_ptr = 1324 - 44 + 64 = 1344
// 1344 % 64 = 0...it is aligned on 64-byte boundry
// 1344 + 100 = 1444...we allocated 164 bytes starting at 1324 so there is 
enough space

I think that will work and it does not rely on any specific APIs. It wastes 
a bit of memory, however.

1


Hi All,
        I am new to device driver development area. I have a very basic
question. I need to allocate memory in my driver which should be aligned to
64 bytes or 2KB or some other value. I want to know that is there any API
available in DDK by which i can allocate memory aligned to a specific value,
if not then what is the other way to achieve it.

Waiting for response
Thanks
Nitin
******************

WDMAUDIODEV addresses:
Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
Unsubscribe:  mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx

URL to WDMAUDIODEV page:
http://www.wdmaudiodev.de/

_________________________________________________________________
Check your PC for viruses with the FREE McAfee online computer scan.  
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

******************

WDMAUDIODEV addresses:
Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
Unsubscribe:  mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx

URL to WDMAUDIODEV page:
http://www.wdmaudiodev.de/
******************

WDMAUDIODEV addresses:
Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
Unsubscribe:  mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx

URL to WDMAUDIODEV page:
http://www.wdmaudiodev.de/

Other related posts: