Does memcpy work for large arrays in structures?

I have a structure that has a dynamic array in it. I have defined two of these structures.

I fill the array in the first structure, then use a line like

memcpy(R->v, A->v, A->n*sizeof(double)

where v is the array that has been dynamically allocated, and n is the number of entries.

R and A are the same type if that matters.

The problem is, the values are not being properyl copied into R. Any idea why? When I try to debug this in totalview, memcpy goes into a function called "very_huge_loop", but no exception or anything is thrown.

the array is approx 188k doubles in length.



It could be memory alignment. Some architectures do not like multi-byte values like double to start on any arbitrary byte address. When you allocate the array memory, you might want to use a function like memalign() instead of malloc(). If you are using new double[n] then it should already be aligned correctly.

Category:arrays Time:2010-06-28 Views:0
Tags: arrays memcpy

Related post

  • How do I know an array of structures was allocated in the Large Object Heap (LOH) in .NET? 2010-05-06

    After some experimenation using CLR Profiler, I found that: Node[,] n = new Node[100,23]; //'84,028 bytes, is not placed in LOH Node[,] n = new Node[100,24]; //'86,428 bytes, is public struct Node { public int Value; public Point Point; public Color

  • What is the most memory efficient way to return large arrays in a C structure from a Matlab C mex function? 2012-02-21

    I have a program which creates a C structure which contains large arrays of various basic data types (ints doubles etc.). What is the most memory efficient way for me to return this data to Matlab from a C mexfunction, while also ensuring all of the

  • array of structures, or structure of arrays? 2009-07-14

    I have a table which is an array of structures I need to store in Java. The naive don't-worry-about-memory approach says do this: public class Record { final private int field1; final private int field2; final private long field3; /* constructor

  • How should I deal with a very large array in Java? 2009-12-16

    I have an algorithm which currently allocates a very large array of doubles, which it updates and searches frequently. The size of the array is N^2/2, where N is the number of rows on which the algorithm is operating. I also have to keep a copy of th

  • Recommended type for a VERY large array(memory wise) in C# 2010-01-15

    I have a large array with around 20k objects in it. Each object has child objects in a big complicated tree structure with arrays in there too. Right now the app is developed using just a simple myObjectType[] myArray and it takes 13 seconds just to

  • LinkedList memory consumption versus List when working with large arrays 2010-05-07

    Can anyone tell me if a linkedlist of structures will be allowed to grow larger than the equivalent List (given that a list uses a doubling strategy for increasing the size of it's internal array). So given a struct that is say 40 bytes (I know about

  • Accessing an Array of Structures through a pointer 2011-05-23

    Here I have a structure definition: typedef struct person { unsigned int ssn, age, height, weight, income; char name[MAXS+1], job[MAXS+1], religion[MAXS+1], major[MAXS+1], minor[MAXS+1], gender; }PERSON; And here I have an in-function array of struct

  • c# fixed arrays - which structure is fastest to read from? 2011-08-03

    I have some large arrays of 2D data elements. A and B aren't equally sized dimensions. A) is between 5 and 20 B) is between 1000 and 100000 The initialization time is no problem as its only going to be lookup tables for realtime application, so perfo

  • Creating an array of structures in C? 2011-11-13

    Possible Duplicate: Defining an array of structures in C? I have a structure DATA which has two fields (int - id and char - dat). I allocate memory to it: DATA *current = malloc(sizeof(DATA)); And assign all the fields: current->id = 1; current-

  • How to get the values of the all objects of a large array and set them to the variables? 2012-01-11

    I'm newbie in PHP. I have to code the system like RSS Reader in this language. So I parsed XML files (which are RSS Feeds) and got a large array which has many sub-arrays. Since it is hard to explain what I need, I decided to add the example code. As

  • What are the pros & cons of using an array of structures versus an array of pointers to a structure? 2012-01-25

    I'm trying to decide which I should use. The pros of pointers to structures that I can think off the top of my head. Less space wasted if you don't use all elements of your array. Less overheard when swapping array elements Any other pro's/con's for

  • What is a best way of defining a very large array (lookup table)? 2012-02-12

    I have to define a large array (lookup table) in a code. It contains 256 elements and takes nearly 1 computer screen. There are two functions that are using this array. I want to define this array under functions, so I could access them very quickly

  • C++ Selection Sort on Array of Structures 2012-03-03

    I am working through a C++ book, and I am a little stuck on one of the challenge questions. I'm working on learning about pointers, and in this particular problem I need to sort an array of structures (using pointers) with a string of a student's nam

  • Memory issues with a very large array in C++ 2012-03-13

    Hi I have the following: struct myStructure { vector<int> myVector; }; myStructure myArray[10000000]; As you can see I have a very large array of a vectors. The problem is that i dont have a priori knowledge of the number of elements I need to

  • reading out large array from a linux kernel module 2012-03-21

    I've searched on this a good deal, though I definitely may have missed something, and I'm coming from reading the and this

  • Accessing members of an array of structures in C++ 2009-07-14

    Working through C++ Primer Plus and am trying to cin data to a dynamically allocated array of structures. One of the items is a char array. How do I write to these struct members? Posting code of my wrong attempt so you can see what I'm trying to do.

  • Is there a good library for sorting a large array of numbers in C? 2009-07-23

    If I have a large array of integers or floats, what is a good algorithm/ implementation for sorting (in C)? It is a bit late in the game for an edit... but I am looking for correctness and speed. --------------Solutions------------- qsort() from the

  • Caching large Arrays to SQLite - Java/ Android 2009-07-28

    Im currently developing a system where the user will end up having large arrays( using android). However the JVM memory is at risk of running out, so in order to prevent this I was thinking of creating a temporary database and store the data in there

  • How do I convert a large array of 8 bit binary values in MATLAB? 2009-10-20

    This is a follow-up question to another SO question of mine. I have a large array of 8 bit binary values that I want to convert back to uint8. I have used Amro's lookupTable solution from the previous question. Now I want to do the reverse. I wanted

Copyright (C), All Rights Reserved.

processed in 0.750 (s). 13 q(s)