From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,55a8252137b5ef97 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!peer-uk.news.demon.net!kibo.news.demon.net!demon!newshub1.home.nl!home.nl!not-for-mail From: Andre Newsgroups: comp.lang.ada Subject: Re: Efficiently setting up large quantities of constant data Date: Thu, 16 Dec 2004 18:11:16 +0100 Organization: @Home Benelux Message-ID: References: NNTP-Posting-Host: cp538812-a.venra1.lb.home.nl Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news4.zwoll1.ov.home.nl 1103217073 15875 84.30.194.114 (16 Dec 2004 17:11:13 GMT) X-Complaints-To: usenet@corp.home.nl NNTP-Posting-Date: Thu, 16 Dec 2004 17:11:13 +0000 (UTC) User-Agent: Mozilla Thunderbird 1.0RC1 (Windows/20041201) X-Accept-Language: en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:6996 Date: 2004-12-16T18:11:16+01:00 List-Id: Dr. Adrian Wrigley wrote: > A similar question I have is how to link in regular files and access > their contents in Ada. > > For example, suppose I have a binary file "distances.dat" containing > the (road) distances between 1000 different cities. This could be a 2MB > file computed by another application. How can I build a single executable > file containing the data and access it from the Ada code? > > I presume this needs to be done at the linker stage, but I don't > see any options to link in non-object files. The obvious alternative > of distributing the data files separately and reading them in > is slower and much less tidy than having a single self-contained binary. > > (I tried Google, but probably didn't use the right search terms...) If you are writting for the Windows platform you have two options: 1. Put it in a resource file and use a resource compiler to add it to your executable. With WIN32 the functions Find_Resource and Lock_Resource you can get a pointer to the data. 2. Use a memory mapped file. This way you also get a pointer to the data and Windows is taking care of loading it into the memory. Data reading using a memory mapped file is just as fast as putting it in the executable. Andr�