Hi all.
This is my situation:
- I have 3 arrays, for example:
unsigned char myArray1[16] =
{
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44
};
unsigned char myArray2[16] =
{ /* like myArray1, different elements of course */ }
unsigned char myArray3[32];
( in my real code the array size is bigger... )
- I would like to merge myArray1 and myArray2 in myArray3 in this way:
myArray3[0] = myArray1[0]
myArray3[1] = myArray1[1]
myArray3[2] = myArray1[2]
myArray3[3] = myArray1[3]
myArray3[4] = myArray2[0]
myArray3[5] = myArray2[1]
myArray3[6] = myArray2[2]
myArray3[7] = myArray2[3]
// ...
So I need to copy alterned lines of n elements (n fixed) from the
arrays and I would like to do without a loop... I need to do this
operation very fast and without using many resources (CPU).
Is it possible?
Any good ideas?
[OT]Ok ok, I know it's OT but my OS is Linux so if someone knows a
system-dependent solution is welcome too...[/OT]
Tnx in advance.
-Mat- 4 1968
Mat wrote: Hi all. This is my situation:
- I have 3 arrays, for example: unsigned char myArray1[16] = { 11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44 }; unsigned char myArray2[16] = { /* like myArray1, different elements of course */ } unsigned char myArray3[32]; ( in my real code the array size is bigger... )
- I would like to merge myArray1 and myArray2 in myArray3 in this way: myArray3[0] = myArray1[0] myArray3[1] = myArray1[1] myArray3[2] = myArray1[2] myArray3[3] = myArray1[3] myArray3[4] = myArray2[0] myArray3[5] = myArray2[1] myArray3[6] = myArray2[2] myArray3[7] = myArray2[3] // ... So I need to copy alterned lines of n elements (n fixed) from the arrays and I would like to do without a loop... I need to do this operation very fast and without using many resources (CPU). [snip]
I think you are looking for something similar to the following:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int a[8];
int h[4]={0,1,2,3}, l[4]={7,6,5,4};
int i;
memcpy(&a[0], l, sizeof(l));
memcpy(&a[4], h, sizeof(h));
for(i=0; i<8; i++)
printf("%d,", a[i]);
return 0;
}
Hope this helps.
cheers,
forayer
--
If you would be a real seeker after truth, it is necessary that at least
once in your life you doubt, as far as possible, all things."
-- Rene Descartes
"Mat" <he***********@ gmail.com> wrote So I need to copy alterned lines of n elements (n fixed) from the arrays and I would like to do without a loop... I need to do this operation very fast and without using many resources (CPU).
Why do you wnat to avoid the loop?
On many platforms, loops are extremely well optimised and often faster than
linear code.
The code is trivial, so what you must do is write it in a few ways, profile
(run the code a thousand times in a loop if resolution isn't good enough),
and choose the fastest. That might be linear code like you posted,it might
be a call to memcpy(), or it might be a loop.
Vimal Aravindashan: memcpy(&a[0], l, sizeof(l)); memcpy(&a[4], h, sizeof(h));
Tnx for your reply Vimal but if I use memcpy in this way I need a loop
to fill every alterned lines and this is not what I want... I don't
have only the first line to fill.
Malcolm: Why do you wnat to avoid the loop? On many platforms, loops are extremely well optimised and often faster than linear code.
I would like to avoid loops because the buffers I work with are 400kb
each and I have to do this operation 10 - 20 times in a second... it
could be too much for the CPU.
The code is trivial, so what you must do is write it in a few ways, profile (run the code a thousand times in a loop if resolution isn't good enough), and choose the fastest. That might be linear code like you posted,it might be a call to memcpy(), or it might be a loop.
I hoped in a strange way to use memcpy :)
To introduce an offset every n bytes...
But I think I will avoid this operation and I probably will work with 2
buffers. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alex Vinokur |
last post by:
Consider the following statement:
n+i, where i = 1 or 0.
Is there more fast method for computing n+i than direct computing that sum?
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
|
by: Evangelista Sami |
last post by:
hello all
i am implementing an application in which a large number of (char *)
is stored into a hash table structure.
As there may be collisions, each (char *) inserted into my hash table
is put into an array. here is the definition of my hash table :
typedef struct
{
short size;
|
by: simkn |
last post by:
Hello,
I'm writing a function that updates an array. That is, given an
array, change each element.
The trick is this: I can't change any elements until I've processed
the entire array. For example, the manner in which I update element 1
depends on several other (randomly numbered) elements in the array.
So, I can't change an element until I've figured out how every element
changes.
|
by: GS |
last post by:
The stdint.h header definition mentions five integer categories,
1) exact width, eg., int32_t
2) at least as wide as, eg., int_least32_t
3) as fast as possible but at least as wide as, eg., int_fast32_t
4) integer capable of holding a pointer, intptr_t
5) widest integer in the implementation, intmax_t
Is there a valid motivation for having both int_least and int_fast?
|
by: Markus.Elfring |
last post by:
Some APIs/SDKs are available to modify settings like "readable",
"writeable" or "executeable".
Examples:
-
http://msdn.microsoft.com/library/en-us/memory/base/memory_protection_constants.asp
- http://www.opengroup.org/onlinepubs/009695399/functions/mprotect.html
- http://en.wikipedia.org/wiki/PaX
Would a companion function fit to the "realloc" programming interface
to
| |
by: Greg Copeland |
last post by:
I am running python on VxWorks. In the course of operation, a vxworks
tasks writes to a reserved area of memory. I need access to this chunk
of memory from within python. Initially I thought I could simply
access it as a string but a string would reallocate and copy this chunk
of memory; which is not something I can have as it would waste a huge
amount of memory. We're talking about something like 40MB on a device
with limited RAM. I...
|
by: Alexis Gallagher |
last post by:
(I tried to post this yesterday but I think my ISP ate it. Apologies if
this is a double-post.)
Is it possible to do very fast string processing in python? My
bioinformatics application needs to scan very large ASCII files (80GB+),
compare adjacent lines, and conditionally do some further processing. I
believe the disk i/o is the main bottleneck so for now that's what I'm
optimizing. What I have now is roughly as follows (on python...
|
by: Michael Sparks |
last post by:
Hi,
I'm interested in writing a simple, minimalistic, non persistent (at this
stage) software transactional memory (STM) module. The idea being it should
be possible to write such a beast in a way that can be made threadsafe fair
easily.
For those who don't know, STM is a really fancy way of saying variables
with version control (as far as I can tell :-) designed to enable threadsafe
|
by: setesting001 |
last post by:
How many of you are running Fast CGI instead of the popular mod_php?
I planning to change to fast cgi since my applications need around
15MB memory to handle a single request, so consider if Apache running
in multi-process mode, serving 300 clients, then it nearly used up all
my memory in my server.
Any experience can share how to handle large concurrent clients for
PHP?
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 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...
| |