function memsetw/memset

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Cchedy
Posts: 22
Joined: Mon Jan 24, 2011 2:49 pm

function memsetw/memset

Post by Cchedy »

hi guys, i m that newbie who ask always for help.
some guys here give me a link to a tutorial which explain how to make your kernel(os if you like) in C. and i really apreched, but this is not why i m writing for :this my problem:
i don't understand what the function of these two function... can any one explain me step by step what is the job of these function and how can code but pls explain how to make but not give the source...
DON'T GIVE ME THE SOURE PLEASE

thanks for your help..
digo_rp
Member
Member
Posts: 233
Joined: Sun Jun 05, 2005 11:00 pm

Re: function memsetw/memset

Post by digo_rp »

If I understood your question, let me try.

memset is like ...

memset(void *src, byte value, size_t amount);

memsetw(void *src, word value, size_t amount);

those functions just fill up your void *src with your byte value how many bytes your specify at size_t amount;

the diference from memsetw is that memsetw just set with a word " 2bytes value" against 1 byte value from memset.

example. you create an array like byte array[0xff];

and you want to fills up that array with 0xf then

memset(array, 0xf, sizeof (array));
and
to use memsetw, word array[0xff];
memsetw(array, 0xff, sizeof(array));

this is just example,
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: function memsetw/memset

Post by gravaera »

Yo,

http://www.cplusplus.com/reference/clib ... ng/memset/

Also, on most standard UNIX installations, you can use "man <posix-or-C-function>" and get a proper listing of its expected behaviour. Do "man memset"
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
Cchedy
Posts: 22
Joined: Mon Jan 24, 2011 2:49 pm

Re: function memsetw/memset

Post by Cchedy »

hi,
with the help of your explication i tried to code my function this way:

Code: Select all

unsigned char *memset(unsigned char *dest, unsigned char val, int count)
{
    unsigned char *n = (unsigned char*)dest;
    while(count-- != 0)
	{
	    *n++ = (unsigned char) val;
    }	
    return dest;	
}
correct me if i m wrong... that's what i understand from your explication and those of tutorial..
thanks for help
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: function memsetw/memset

Post by Tosi »

If you don't understand simple functions such as memset, I would definitely not recommend OS development as a project.
Cchedy
Posts: 22
Joined: Mon Jan 24, 2011 2:49 pm

Re: function memsetw/memset

Post by Cchedy »

what i have done is wrong? than correcte me
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: function memsetw/memset

Post by Tosi »

First off, the more standard prototype for memset is

Code: Select all

void * memset ( void * ptr, int value, size_t num );
As for your implementation, there are a lot of redundant typecasts and some other minor things that might affect performance.
Whether it works or not, you won't know until you test it.
Cchedy
Posts: 22
Joined: Mon Jan 24, 2011 2:49 pm

Re: function memsetw/memset

Post by Cchedy »

thanks but i m actually reading a tutorial the tutorial is who give me this parameters and give me the order to code it but he don't say what i have to do for these to functions: there is mempcy which is explained well and it 's so easy but the others are not explained.
maybe you forget that i m doing a kernel in C.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: function memsetw/memset

Post by Tosi »

I know you are doing a kernel in C. What I am saying is that you should have enough experience in C before coming to kernel development that you know exactly what memset/memcpy are and how to implement them.
Cchedy
Posts: 22
Joined: Mon Jan 24, 2011 2:49 pm

Re: function memsetw/memset

Post by Cchedy »

ok...
User avatar
Karlosoft
Member
Member
Posts: 277
Joined: Thu Feb 14, 2008 10:46 am
Location: Italy
Contact:

Re: function memsetw/memset

Post by Karlosoft »

Memset is a function provided by the stdlib so you can't know how the complier implements it. You know only how to use it so the question of Cchedy is good. The C programmer doesn't need to know "how it works". Now in osdev things are a little different, so I can't understand why you have to be so hard with a person which has only asked a question.

@ Cchedy You should provide some portable types in your code like uint8 or size_t. They aren't required but they makes you code easier to be ported to an other architecture.
Cchedy
Posts: 22
Joined: Mon Jan 24, 2011 2:49 pm

Re: function memsetw/memset

Post by Cchedy »

thanks for your help!!!
evry time here when i ask a question they come always to discourage me. you are the seconde person who don't do the same really thanks ...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: function memsetw/memset

Post by Combuster »

Karlosoft wrote:The C programmer doesn't need to know "how it works". Now in osdev things are a little different, so I can't understand why you have to be so hard with a person which has only asked a question.
Your logic is flawed: for memset (and the exact same argument holds for memcpy and others), how it does it is identical to what it does: fill n bytes starting from location x with value y. Now, someone who can't reliably write such a function does not meet the requirements to pass a formal C programming course (something code monkeys can do), let alone start with OS development (something code monkeys can not do, only real programmers).

@OP: Have you ever written something fairly complex like a graphics engine? Are you able to do that using only the manuals and other existing documents, and not asking any live person for help? If the answer is no, then OS development is not (yet) for you.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Cchedy
Posts: 22
Joined: Mon Jan 24, 2011 2:49 pm

Re: function memsetw/memset

Post by Cchedy »

i m a pro in C++only and with lib QT but C i don't really used for very simple things i never used memcpy or memset/w.
i guess what you will say: you don't have the required to be here... bla bla yaya ...
but you forget that you was like me.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: function memsetw/memset

Post by Chandra »

Cchedy wrote:i m a pro in C++only and with lib QT but C i don't really used for very simple things i never used memcpy or memset/w.
i guess what you will say: you don't have the required to be here... bla bla yaya ...
but you forget that you was like me.
Okay, I am not here to discourage you but why don't you chose C++ as your OSDEV language?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Post Reply