How use SetIntArrayRegion with std::vector int ?

I have a vector of ints that i want to put into a jintArray. How do I do this?
When I tried the below code, it didn't work but instead when i printed out the int values on the java side, they were all messed up.
jintArray arr = env->NewintArray( intVector.size() );
env->SetintArrayRegion( arr, 0, intVector.size(), ( jint * ) &( intVector ) );This returns weird values. What am I doing wrong?

This isn't a Java/JNI-specific issue. Your code also wouldn't work if you tried to do this:
void foo( int* );
void bar() {
    vector<int> a(10);
    foo( (int*)&a );
}Hint: using a cast is a bad idea. It's wrong for the same reason the following code is wrong:
void foo( double* );
void bar() {
    double d = 42.0;
    foo( (int*)&d );
}You can't just use a cast as a sledge-hammer and magically expect the right thing to happen. In your original code, you're passing the address of the C++ vector object as if it were the address of a plain old C-style array of int.
Using old-style casts is a bad idea in general. This is why new-style casts were added to the language. Had you tried to use:
    static_cast<int*>( &intVector )the compiler would have correctly complained. Old-style casts assume you know what you're doing. In this case, your old-style cast is equivalent to a reinterpret_cast<int*>.
That aside, there's intentionally no way to convert a vector<T> into the address of its first element because there's no guarantee that the implementation of vector will store array elements contiguously.

Similar Messages

  • How use multithead with socket

    How use multithead with socket
    I need do a client and server program that accept multitherad issue
    Thanks who can help me

    you'd have to do something like this:
    (this is all assuming you want to read Strings from the socket. setSoTimeout works for any read() call to the InputStream associated with the Socket)
    ServerSocket ss = new ServerSocket(myPort);
    Socket s = ss.accept();
    s.setSoTimeout(5*60*1000); // 5 mins * 60 secs * 1000ms
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    boolean running = true;
    while(running)
    try
    String readIn = in.readLine();
    // do whatever you want with the data read
    catch(SocketTimeoutException)
    running = false;
    Now. That's what I think needs to be done. I don't have Java on the machine I'm currently on, so I can't test/verify it, but it goes something like that.
    Good luck,
    Radish21

  • How use jdbc with swing ? i am new in this concept.

    hi
    freinds,
    i am new in java can any one give the example which explain the how to use jdbc with swing.
    thanks in advace.
    satish
    thanks.

    See here  >  http://support.apple.com/kb/HT4236
    More info in the User Guides for your Devices...

  • How use Tomcat with MySQL

    Can anybody suggest me as how to use Tomcat with MySQL server.
    Thanks in advance.
    Khiz_eng

    add the classpath to the JDBC-driver to the tomcat-
    environment (I did it in tomcat.sh)
    Then put your code accessing MySQL into a servlet....
    You can put the user-ID and the password into a session-
    object or read them in as parameters.
    The book 'core Servlets and Java Server Pages' from
    Marty Hall gave me a lot information.
    Regards
    Fredy

  • How use REPORT_DESTYPE with WebDAV

    Hi,
    How can I use the RUN_REPORT_OBJECT command to send report to Portal via WebDAV. If I try:
    SET_REPORT_OBJECT_PROPERTY( repid, REPORT_DESTYPE,WEBDAV);
    there is an error:
    identifier "WEBDAB" must be declared !
    In the Document " Oracle Application Server 10G -Integrating Oracle Reports in Oracle Forms Services applications" It said the REPORT_DESTYPE may be FILE, PRINTER, MAIL or CACHE only. What about other types like OraclePortal and WebDAV ?

    Hi Fang,
    As far as I know, SQL Server Reporting Services (SSRS), have no permission extension. In Reporting Services, it is use role-based security to grant user access to a report server. There are two types of roles: Item-level roles and System-level roles.
    Based on my test, if we assign user with System User System-level role, the user will have permission to user Report Builder to create report. However, if we only assigned Browser or Report Builder Item-level role to the user, he/she will have no permission
    to publish the report to the report server. In this situation, although user have permission user Report Builder to edit the report, it will have no effect of the report in report server. User who has assigned Browser or Report Builder Item-level role will
    have no permission to delete report in the report server.
    There is an article about Setting Permissions in Reporting Services, you can refer to it.
    http://technet.microsoft.com/en-us/library/aa337491(v=sql.105).aspx
    Hope this helps.
    Regards,
    Alisa Tang
    Alisa Tang
    TechNet Community Support

  • How use locator with sax to get line number of an element?

    dear friends,
    it's clearly stated in subject. after trying for hours, i still couldn't figure out how to get line numbers. my class extends defaulthandler. please help.
    ozgur

    hi
    i am also struggling with same problem
    someone plssssssss help.....
    how can i use Locator to get line number of the XML document.
    in my extended DefaultHandler class i have just implemented this,
    public void setDocumentLocator(Locator location) {
         lineNumber = location.getLineNumber();
    but no help...
    how to register my parser to the documnet locator events?
    plzzzzzzz help...
    -Soni

  • How use xml with namespaces

    I have the following xml which is output from Oracle Bpel.
    <OglRapportPerAdresnrResponse xmlns="http://www.itude.com/technology/Ogl/RapportPerAdresnrResponse">
    <AdresGegevens>
    <Adresnr>54321</Adresnr>
    <Straatkode>12345</Straatkode>
    </AdresGegevens>
    </OglRapportPerAdresnrResponse>
    If i remove the namespace info everything works fine but with the namespace info the output is empty if i insert e.g. <Adresnr> into a template. The field browser shows everything fine and also the value but when rendering a PDF it disappears. I read in the user guide that i need to declare the namspace in a form field like <?namespace:namespace name= namespace url?> but how do i do that with the above namespace notation where the namespace name is empty ?
    Regards,
    Andre

    Hi Tim,
    I found part of the solution but i am still stuck when i need to use <?for-each?> tags. When i use the following XML:
    <OglRapportPerAdresnrResponse xmlns="http://www.itude.com/technology/Ogl/RapportPerAdresnrResponse">
         <AdresGegevens>
              <Adresnr>8391</Adresnr>
              <Straatkode>11070</Straatkode>
         </AdresGegevens>
         <Basisgegevens>
              <paramPResult xmlns="urn:generated.ws.kgb.itude.com">
                   <paramAdresnr>8391</paramAdresnr>
                   <paramGegevenstype>GEBRUIK</paramGegevenstype>
              </paramPResult>
              <paramPResult xmlns="urn:generated.ws.kgb.itude.com">
                   <paramAdresnr>8391</paramAdresnr>
                   <paramGegevenstype>STADSDEEL</paramGegevenstype>
              </paramPResult>
         </Basisgegevens>
    </OglRapportPerAdresnrResponse>
    I read the xml file in Word. I then have access to the fields but when i select AdresGegevens/Adresnr the output is not rendered. The namespace is a default namespace for that element. I found out that if i define a namespace like <?xmlns:bpel=http://www.itude.com/technology/Ogl/RapportPerAdresnrResponse?> and then access the AdresGegevens/Adresnr through <?bpel:Adresnr?> it works!
    I then defined a second namespace <?xmlns:bpel2=urn:generated.ws.kgb.itude.com?> and tried to render the paramPResult tags with:
    <?for-each:paramPResult?>
    <?bpel2:paramAdresnr?>
    <?bpel2:paramGegevenstype?>
    <?end for-each?>
    But the above does not work. Any ideas?
    Regards,
    Andre Jochems

  • How use USB with VISA resource name?

    Hi, 
    I'm new at LabVIEW and I'm working on a code that has to acquire data from a measurement device.This device only has a USB output so I have to work with it. As far as know the block that is used to refer a external port is VISA resource name. I have installed a driver that recognizes the serial ports, and they appear in the list of VISA resource file at front panel. So I figured that installing the product's USB driver so the USB's ports would appear. I installed and nothing of USB ports. I don't know it is that simple or working with USB ports is a little bit harder. I've tried a lot of things and nothing worked so here I am.
    PS: I have noticed that the driver's version is 64 bits (my pc is 64 bits)  and my LabVIEW version is 32 bits, so could that be the problem?
    The device by the way is Digital Analyzer WT500, Yokogawa.
    Thank you.
    Solved!
    Go to Solution.

    Victor,
    the suggestion of Instrument Driver is to make more easy using the instrument. 
    Normally, you should install a windows drive from manufacturer (if it isn't installed, the instrument will appear like a pendrive in device manager) and the NI VISA. But for some instruments, the manufacturers have API's that uses NI VISA to communicate with your equipments.
    So check if your instrument appear correctly in device manager (as indicated by Yokogawa). If not, check if Yokogawa has an appropriated driver for this instrument and install it. 
    Is it clear?
    If you prefer, contact NI Brazil Support by website or by phone (11)3149-3149 Ext 3.
    Ricardo Ramos
    Engenheiro de Vendas - Sul
    National Instruments Brasil

  • E72 - How Use email with 3G or WLAN connection

    1) CONNECTION CONFIGURATION
    To configure the Phone to prompt always the selection of Access Point to use, you should go here:
    Menu -> Ctrl. Panel -> Settings -> Connection -> Destinations.
    then, with in the Options menu, select Default Connection, and set it as ASK ALWAYS.
    2) EMAIL CONFIGURATION 
    Each email account allow the configuration of the default "Destination" that should be used:
    Menu -> Email -> Settings -> "Your Account" -> Mailbox Setting -> Advanced Mailb. Settings ->
                      - > Incoming email -> Access point in use := ASK ALWAYS
                       -> Outgoing email -> Access point in use := ASK ALWAYS
    If you use the Push Email functionality, the configuration of access point is here:
    Menu -> Email -> Settings -> "Your Account" -> Account Settings -> Account Information -> Access Point 
    But for this functionality it's not possible to set as ASK ALWAYS, you should configure a fixed access point.
    I hope that now you are able to use the email (not only email, but all apps) with the correct connection.
    Bye from Italy.
    Edi

    Hi, Thanks for the info.... I also looking for the solution to set/assign "connection group" instead of define single connection... but i guess this is not feasible in current firmware... hope to available future firmware relase.
    Regards,
    Anandharaj
    www.raj2u.net :: E72-1 | RM-530 | 023.007

  • How use proxyclient with Reportexecution2005?

    Hi,
    I want to run a report from a SSRS-server in my C# code (i want to export the report in a 2007-2010 excel format).
    I know that I need to use the Reportexecution2005 WCF-service but I have never done this before and I can't find any nice examples on the web...
    The most examples doesn't deal with a "Soap-client" (they seems to use the webservice-class) and use another kind of Reder-method (with differende parameters).
    Here is my beginning:
    varclient =
    newReportExecutionServiceSoapClient();     
    var  result = client.Render(???)
    Hope someone can help me to with the code...
    regards,
    Marius H Enerud

    Hi Marius,
    On the basis of the description, I understand that you intend to use ReportExecution2005 web service to render reports in Excel format.
    The Reporting Services Execution Web service allows developers to programmatically process and render reports from report server. To process a specific report and render it in the specified format, we can use the “Render” method in the ReportExecutionService.
    Here, you can see these steps below to render the report:
    1. In the custom application, add a web service reference. The endpoint should be:http://<servername>/reportserver/ReportExecution2005.asmx
    2. Use the following code to render the report in the specified format:
    using System;
    using System.IO;
    using System.Web.Services.Protocols;
    using myNamespace.MyReferenceName; 
    class Sample{   
    static void Main(string[] args)   
    ReportExecutionService rs = new ReportExecutionService();       
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;        rs.Url= "http://myserver/reportserver/ReportExecution2005.asmx";         // Render arguments       
    byte[] result = null;       
    string reportPath = "/AdventureWorks Sample Reports/Employee Sales Summary";     
    string format = "Excel";       
    string historyID = null;       
    string devInfo = null; // Prepare report parameter.       
    ParameterValue[] parameters = new ParameterValue[3];       
    parameters[0] = new ParameterValue();       
    parameters[0].Name = "EmpID";       
    parameters[0].Value = "288";       
    parameters[1] = new ParameterValue();       
    parameters[1].Name = "ReportMonth";       
    parameters[1].Value = "6";  // June       
    parameters[2] = new ParameterValue();       
    parameters[2].Name = "ReportYear";       
    parameters[2].Value = "2004";       
    DataSourceCredentials[] credentials = null;       
    string showHideToggle = null;       
    string encoding;       
    string mimeType;       
    string extension;       
    Warning[] warnings = null;       
    ParameterValue[] reportHistoryParameters = null;        string[] streamIDs = null;               
    ExecutionInfo execInfo = new ExecutionInfo();        ExecutionHeader execHeader = new ExecutionHeader();        rs.ExecutionHeaderValue = execHeader;       
    execInfo = rs.LoadReport(reportPath, historyID);        rs.SetExecutionParameters(parameters, "en-us");         String SessionId = rs.ExecutionHeaderValue.ExecutionID;        Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);       
    try       
    result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);           
    execInfo = rs.GetExecutionInfo();            Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);
    catch (SoapException e)       
    Console.WriteLine(e.Detail.OuterXml);       
    }        // Write the contents of the report to an PDF file.       
    try       
    FileStream stream = File.Create("report.pdf", result.Length);           
    Console.WriteLine("File created."); 
               stream.Write(result, 0, result.Length);           
    Console.WriteLine("Result written to the file.");           
    stream.Close();      
    catch (Exception e)       
    Console.WriteLine(e.Message);       
    For more information, please see:
    ReportExecutionService.Render Method
    ReportExecution2005 Namespace
    If I have any misunderstanding, please feel free to contact me.
    Regards,
    Heidi Duan
    If you have any feedback on our support, please click
    here.
    Heidi Duan
    TechNet Community Support

  • How use Cookies with flex

    Hi,
    Can we use cookies in flex. If so, can any body give me the
    sample code for that.
    Thanks
    Satish KC.

    Rather than ordinary cookies, use Local Shared Object. It is
    much more powerful than standard cookies.
    I'll look for an example. What version of Flex are you using?
    Tracy

  • How use badi with 0crm_sales_act_1 datasource

    Hi
    i am working on crm extractor, 0crm_sales_act_1.To meet my requirements i need to enhance it, it is based on BADi.
    I don't know the BADi. but i am having some abap knowledge.
    If you send me exemple or program.
    best Regards,

    thx

  • Is it possible to display the content of complex mutlidimensional datastructures (e.g. std::vectors (dim = 2) of (non-primitive) types) in Xcode debugger?

    Hi,
    First, let me say that I like Xcode and coding in OS X. However, there is something I miss:
    Let me demonstrate what i mean:
    This is the representation of a 2D-Vector in Xcode Debugging environment:
    v          'std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >'          [{...}]
    0          'std::vector<int, std::allocator<int> >'          [{...}]
    1          'std::vector<int, std::allocator<int> >'          [{...}]
    2          'std::vector<int, std::allocator<int> >'          [{...}]
    3          'std::vector<int, std::allocator<int> >'          [{...}]
    4          'std::vector<int, std::allocator<int> >'          [{...}]
    5          'std::vector<int, std::allocator<int> >'          [{...}]
    6          'std::vector<int, std::allocator<int> >'          [{...}]
    7          'std::vector<int, std::allocator<int> >'          [{...}]
    8          'std::vector<int, std::allocator<int> >'          [{...}]
    So, the above representation is what I would call bad (even useless).
    The problem is that the current Linux Kernel (3.1.1) has some problems with the new MBA 2011 (which is really sad) so I can not show you the representation of a 2D-Vector in Qt-Creator for Linux right now (I'm not sure if the Qt-Creator for OS X could display the content properly, since I've never tried it). But you can believe me, that the represantation would look something like the one in Eclipse (which would be a good representation).
    So my question: is there a "fix" for this?

    What you want is a custom data formatter. I would give you some links, but my iPad wants to convert them into the documentation viewer.
    You aren't going to find much help with C++ debugging. While Apple's Clang has made great improvements in C++ support compared to GCC, C++ is really not something that Mac or iOS programmers typically use. The Cocoa containers and objects are so much more versatile. You kind of have to have a masochist streak and a 7 year development schedule to use C++. C++ is experiencing a bit of a resurgence, especially in defense markets. For a long time, compilers had such poor support for C++ that it just wasn't possible. After simplifying the language a little, compilers can now compile and link C++. Consultants have realized they can provide C++ services and burn though billable hours better than any other language on the market. Independent developer, however, don't have those schedules and budgets so they tend to use NSArray. Xcode supports it better in the debugg and, chances are, you don't need to debug it anyway. There are a number of matrix classes built on Cocoa.

  • Dbx crashes when (incorrectly) using .. syntax on vectors

    Given code:
    #include <vector>
    int main() {
            std::vector<int> a(2);
            return 0;
    }Compile and run with dbx:
    % CC -g t.cc
    % dbx -q a.out
    (dbx) stop at 3
    (2) stop at "t.cc":3
    (dbx) run
    Running: a.out
    (process id 25017)
    stopped in main at line 3 in file "t.cc"
        3           std::vector<int> a(2);
    (dbx) p a[0..1]
    dbx: internal error: signal SIGSEGV (no mapping at the fault address)
    dbx's coredump will appear in /tmp
    Abort (core dumped)Understand that .. syntax is not supported on c++ vectors, but would appreciate another
    errormessage.
    version of "/opt/SUNWspro/bin/dbx": Sun Dbx Debugger 7.5 Patch 121023-01 2006/02/09

    Actually command "p a[0..1] is considered legal syntactically
    after we added array slice support in dbx. Problem here is
    that this command involves a target function call and dbx
    failed to validate the type of the array_slice before converting
    and passing it to method operator "[]".
    I will enter this problem to our bug database. Thanks for the
    report.

  • How to read a C structure with string and int with a java server using sock

    I ve made a C agent returning some information and I want to get them with my java server. I ve settled communication with connected socket but I m only able to read strings.
    I want to know how can I read strings and int with the same stream because they are sent at the same time:
    C pgm sent structure :
    char* chaine1;
    char* chaine2;
    int nb1;
    int nb2;
    I want to read this with my java stream I know readline methode to get the first two string but after two readline how should I do to get the two int values ?
    Any idea would be a good help...
    thanks.
    Nicolas (France)

    Does the server sent the ints in little endian or big endian format?
    The class java.io.DataInputStream (with the method readInt()) can be used to read ints as binary from the stream - see if you can use it.

Maybe you are looking for