Hi,
I'm new to c# an missing functions like memcmp and memcpy from C.
Is there something similar ?
cu
Alex 7 12769
Alex,
To copy value types (such as structures) what you need to do is just using
the assignment operator; this will make a shallow copy of the struct
members.
I would say almost all reference types that represent block of data in the
memory (e.g. arrays and collections) CopyTo
method. Actually this method is defined in the ICollection interface.
The other way you can create a copy of an object's data is to call Clone if
the type implements ICloneable interface.
In addition there is a method defined on the level of the Object class
called MemberwiseClone . This mehod creates a shallow copy of the object. The
method is protected and is meant to be used for implementing *clone*.
As far as string comparison goes you can use the CompareXXXX methods of
the String class.
--
HTH
Stoitcho Goutsev (100)
"Alex Stark" <st****@online. nospam> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Hi,
I'm new to c# an missing functions like memcmp and memcpy from C. Is there something similar ?
cu Alex
Hi Stoicho,
thanks for your answer. But I don't really understand what you mean.
All I have is a bytearray b1 and I want to kow is, if a second bytearray b2
is part somewhere in b1.
In C the code is a simple :
int section_init(uc har *tra, int tralen)
{
int i, j=0;
uchar buf[256];
if (memcmp(tra+4, "LOCKED", 6))
return(0);
............... ....
}
How is such a simple think in C# realizable ? Sure, I can build a string
and in this case this will be the easiest way.....but I think, there are
some
more complex issues, where string conversation will not the best way.
Thanks for your help !!!!!!!!!!!
Alex
"Stoitcho Goutsev (100)" <10*@100.com> schrieb im Newsbeitrag
news:O6******** ******@TK2MSFTN GP12.phx.gbl... Alex,
To copy value types (such as structures) what you need to do is just using the assignment operator; this will make a shallow copy of the struct members.
I would say almost all reference types that represent block of data in the memory (e.g. arrays and collections) CopyTo method. Actually this method is defined in the ICollection interface.
The other way you can create a copy of an object's data is to call Clone if the type implements ICloneable interface.
In addition there is a method defined on the level of the Object class called MemberwiseClone . This mehod creates a shallow copy of the object. The method is protected and is meant to be used for implementing *clone*.
As far as string comparison goes you can use the CompareXXXX methods of the String class.
-- HTH Stoitcho Goutsev (100)
"Alex Stark" <st****@online. nospam> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Hi,
I'm new to c# an missing functions like memcmp and memcpy from C. Is there something similar ?
cu Alex
"Alex Stark" <st****@online. nospam> wrote in
news:e4******** ******@TK2MSFTN GP10.phx.gbl: Hi Stoicho,
thanks for your answer. But I don't really understand what you mean. All I have is a bytearray b1 and I want to kow is, if a second bytearray b2 is part somewhere in b1.
In C the code is a simple :
int section_init(uc har *tra, int tralen) { int i, j=0; uchar buf[256];
if (memcmp(tra+4, "LOCKED", 6)) return(0); ............... ... }
How is such a simple think in C# realizable ? Sure, I can build a string and in this case this will be the easiest way.....but I think, there are some more complex issues, where string conversation will not the best way.
Thanks for your help !!!!!!!!!!!
Alex
"Stoitcho Goutsev (100)" <10*@100.com> schrieb im Newsbeitrag news:O6******** ******@TK2MSFTN GP12.phx.gbl... Alex,
To copy value types (such as structures) what you need to do is just using the assignment operator; this will make a shallow copy of the struct members.
I would say almost all reference types that represent block of data in the memory (e.g. arrays and collections) CopyTo method. Actually this method is defined in the ICollection interface.
The other way you can create a copy of an object's data is to call Clone if the type implements ICloneable interface.
In addition there is a method defined on the level of the Object class called MemberwiseClone . This mehod creates a shallow copy of the object. The method is protected and is meant to be used for implementing *clone*.
As far as string comparison goes you can use the CompareXXXX methods of the String class.
-- HTH Stoitcho Goutsev (100)
"Alex Stark" <st****@online. nospam> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Hi,
I'm new to c# an missing functions like memcmp and memcpy from C. Is there something similar ?
cu Alex
Have a look at the Buffer class.
Alex,
In .NET array of bytes is different than array of chars which is totally
different than strings. Further mode Char is 16 bit where Byte is 8.
If you want to look for a sub string use strings. Otherwise you
need to write your own code for lookup consecutive bytes in a byte array.
There is no equivalent of memcmp in managed framework.
--
HTH
Stoitcho Goutsev (100)
"Alex Stark" <st****@online. nospam> wrote in message
news:e4******** ******@TK2MSFTN GP10.phx.gbl... Hi Stoicho,
thanks for your answer. But I don't really understand what you mean. All I have is a bytearray b1 and I want to kow is, if a second bytearray b2 is part somewhere in b1.
In C the code is a simple :
int section_init(uc har *tra, int tralen) { int i, j=0; uchar buf[256];
if (memcmp(tra+4, "LOCKED", 6)) return(0); ............... ... }
How is such a simple think in C# realizable ? Sure, I can build a string and in this case this will be the easiest way.....but I think, there are some more complex issues, where string conversation will not the best way.
Thanks for your help !!!!!!!!!!!
Alex
"Stoitcho Goutsev (100)" <10*@100.com> schrieb im Newsbeitrag news:O6******** ******@TK2MSFTN GP12.phx.gbl... Alex,
To copy value types (such as structures) what you need to do is just using the assignment operator; this will make a shallow copy of the struct members.
I would say almost all reference types that represent block of data in the memory (e.g. arrays and collections) CopyTo method. Actually this method is defined in the ICollection interface.
The other way you can create a copy of an object's data is to call Clone if the type implements ICloneable interface.
In addition there is a method defined on the level of the Object class called MemberwiseClone . This mehod creates a shallow copy of the object. The method is protected and is meant to be used for implementing *clone*.
As far as string comparison goes you can use the CompareXXXX methods of the String class.
-- HTH Stoitcho Goutsev (100)
"Alex Stark" <st****@online. nospam> wrote in message news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Hi,
I'm new to c# an missing functions like memcmp and memcpy from C. Is there something similar ?
cu Alex
Stoitcho Goutsev (100) <10*@100.com> wrote: In .NET array of bytes is different than array of chars which is totally different than strings. Further mode Char is 16 bit where Byte is 8. If you want to look for a sub string use strings. Otherwise you need to write your own code for lookup consecutive bytes in a byte array.
There is no equivalent of memcmp in managed framework.
Note that there's Buffer.BlockCop y, which isn't really an equivalent,
but can sometimes be used in the same situations.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Hello Jon Skeet [C# MVP], Stoitcho Goutsev (100) <10*@100.com> wrote:
In .NET array of bytes is different than array of chars which is totally different than strings. Further mode Char is 16 bit where Byte is 8. If you want to look for a sub string use strings. Otherwise you need to write your own code for lookup consecutive bytes in a byte array. There is no equivalent of memcmp in managed framework. Note that there's Buffer.BlockCop y, which isn't really an equivalent, but can sometimes be used in the same situations.
Note that memcmp = memory compare, as he's searching for a byte sequence
in a larger array.
Don't think there's anything present in the .NET framework that does exactly
that, at least neither Buffer or Array seems to have any methods that compare
parts of arrays against each other.
--
Lasse Vågsæther Karlsen http://usinglvkblog.blogspot.com/
mailto:la***@vk arlsen.no
PGP KeyID: 0x2A42A1C2
Lasse Våqsæther Karlsen wrote: There is no equivalent of memcmp in managed framework. Note that there's Buffer.BlockCop y, which isn't really an equivalent, but can sometimes be used in the same situations.
Note that memcmp = memory compare, as he's searching for a byte sequence in a larger array.
Oops - you're absolutely right. I misread Stoitcho's post. Doh!
Jon This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: rajkumar |
last post by:
I have a struct like
struct MyStruct
{
int a;
int b;
int c:
bool d;
bool e;
}
|
by: blueblueblue2005 |
last post by:
hi, I am reading the description of memcmp and strcmp, it seems there
is no big difference between these two functions. except that memcmp
takes void pointer parameters. so why string.h has these two functions
doing the same thing?
|
by: Sidney Cadot |
last post by:
Hi all,
Just browsing through my newly-acquired C99 spec, I was reading on the
memcmp() function (7.21.4.1). It has a rather peculiar wording:
int memcmp(const void *s1, const void *s2, size_t n);
1. The memcmp function compares the first n characters of the object
pointed to by s1 to the first n characters of the object pointed to by s2.
|
by: Preets |
last post by:
Hi,
Can anybody please tell me the difference between memcmp() and
strncmp() functions ?
|
by: system55 |
last post by:
which of the 2 commands are applicable in comparing an array of unsigned chars?
if(strcmp(aAbsCylNumHigh, bAbsCylNumHigh)<=0 && strcmp(aAbsCylNumLow,bAbsCylNumLow)<=0 && strcmp(aSecNum,.bSecNum)<0 )
or
if(memcmp(aAbsCylNumHigh, bAbsCylNumHigh,2)<=0 && memcmp(aAbsCylNumLow,bAbsCylNumLow,2)<=0 && memcmp(aSecNum,.bSecNum,2)<0 )
| |
by: Martin |
last post by:
Please consider the following code fragment. Assume UINT32 is a typedef
suitable for defining variables of 32 bits, and that ui32 is initialised.
UINT32 ui32;
/* ... */
/* assume ui32 now is holding a value in uc's range */
unsigned char uc = (unsigned char) ui32; /* tell Lint you know target
type is smaller */
cmos->uc = uc;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |