Assorted VO tips

Everyone seems to discover a different subset of functionality so some of these may be obvious to you.

Importing PRG’s is easier than I realised. When creating a new module and associating it with a PRG you can actually specify multiple PRG’s to create multiple modules.

VOPP creates a PRG file when building a DLL using the Single app build and System builder. You can use this PRG file instead of the AEF created for the DLL for your imports. If you do this then whenever you change your DLL you will just need to touch the module linked to the PRG to get the changes. No more deleting the application and reimporting the AEF.

Advertisements

The -h flag

The -h flag is available on many file utilities on linux. It’s a useful addition for those of us who are human and like to understand the output of our utilities. It’s normally labelled as the flag for human readable output in the help. This normally means getting your file sizes reported in K, Mb and Gb. Utilities such as df, du and ls -l allow the use of this flag — a most useful addition.

VO 2.5 Memory tips

This is a note I wrote some time ago about VO 2.5 and there is an addition there about the then new VO 2.7

Visual Objects applications operate within a fixed amount of memory. If you do not have enough the applications tend to die in horrible and unusual ways. To up the amount the application has you can use either of two methods. One is to call DynSize in the application and get yourself some more memory or the second is to set a registry key to make the application load with more at startup.

The key you need is HKEY_CURRENT_USER\Software\ComputerAssociates\CA-Visual Objects Applications\Runtime

The Value you wish to look at is MaxDynSpace. You may need to create this value, if you do create it as a Dword key. Entering the value in hex is by far the easiest approach. The default value usually used is 1000000 which is 16 Mb. A value of 2000000 (32 Mb) is a reasonable alternative to give your app a better chance.

This value is read by the running application, not at compile time for a default setting so if you have discovered that your application will always need at least x amount of memory use the DynSize call to ensure it will run properly on your machine. The registry key is particularly useful if you are running a 3rd party application.

There is a bug in the VO 2.5 implementation of the DynSize call. The DynSize call is intended to allocate a block of memory to start with to prevent page faults early on. If you use more than this amount of pages however when the garbage collector kicks in it will reduce the number of pages down to the number specified by the DynSize, thereby losing the extra pages allocated and anything in them. This commonly causes crashes. The simplest workaround is to set the DynSize to be so high you don’t reach it. Alternatively upgrade to VO 2.7 where the bug has been fixed.

Python bits to remember

I’ve been going to the West Midlands Python User Group for a bit now and thanks to John Pinner of Clockwork software systems excellent sessions I have learnt a few more things about Python.

Use dir to examine things.

Use help to read the help about things.

Use sys.path to see where Python is looking for files.

import sys
sys.path

If you need to add another path to the search list you can use a .pth file to specify a path. There are commonly some in /usr/lib/python*/site-packages/. Sometimes they just point to a directory within that dir, othertimes it’s a directory far away. It appears that they can contain python but all you need is a path.

If you need to add a search path to apache you can do it like this,
PythonPath "['/usr/local/src/'] + sys.path"

ltrace and the -f flag

Debugging running programs under linux can be extremely simple. The program ltrace allows you to watch all the library calls being made which helps locate where a program is going wrong. It can also allow you to notice some basic performance bottlenecks.

The -f flag is also particularly useful for watching a servers progress, and in particular a daemon that crashes. The typical method of initialisation for a daemon is to fork off, stop responding to various signals and then in the new process do the actual initialisation. If the daemon decides to terminate in the usual verbose unix fashion then you have a problem. Using the -f flag means that ltrace also monitors all the processes created by forking and allows you to see what actually caused it to finish.

Heme – a linux hex editor

Heme’s a simple hex editor for Linux. It actually compiles and works on Mac OS X too but some of the key mappings aren’t quite right. It’s on sourceforge at http://sourceforge.net/projects/heme/

I actually made a small contribution to it’s codebase too. Including at least one bug! I also fixed said bug when I spotted it 😉

The advantage of it is that it’s so simple it’s really likely to compile. It’s functionality is a bit limited but I could always expand it some more. A lot of the other hex editors I found wouldn’t compile or had dependencies I didn’t like.

Loopback!

Have you ever wanted to demo something in a pub but your software needs to be on a network? Trying to demo something that needs a network adapter installed for some reason? I’m going to demo a system tonight and I’m going to run a webserver in a virtual machine and then connect to that from the desktop. I don’t actually need any wires for the network but the two ‘computers’ do need networking.

This situation calls for the ‘Loopback’ adapter.

  • Go to the add hardware wizard and add hardware manually.
  • Select the microsoft devices
  • Find the Loopback network adapter and select it
  • Assign the adapter a static IP address.
  • Now tweak the virtual machines configuration so that it can see the network ‘card’.
  • Load the virtual machine.
  • Assign a static IP address to it’s version of the network card. Note that it might not be reporting that it’s a loopback adapter.

Now the two machines can communicate and you can demo your software.

You might find this useful for software that simply requires a network adapter. I’m told reliably that the Advantage really doesn’t like to be demo’d without a network connection being present.

There are also another variety of uses outlined in these posts, Setting Up A Virtual Pc ‘complex’ Network and Networking Settings in Virtual PC where I found out how to do what I needed.

Fixing a hard disk

Just recently we installed a new sata disk at work. When we did the other one that we installed at the start of the year stopped being visible in Windows. It turned into a ‘dynamic’ disk according to the disk manager.

A search of the interweb came up with all sorts of fun suggestions like reformatting. There was one article that suggested that it was simply the type of the partition that got changed in the master boot record. It said that you just needed to change the byte back to it’s original value and everything would be peachy.

Rather than look for the utils that it suggested I just fired up a box with the Ubuntu boot/install CD and used DD. From memory the command dd if=/dev/sda of=bootsect.bin bs=512 count=1 retrieved the boot sector.

Note that the exact hard disk device you specify is very important. Typically you have a device for each partition of the hard disk, normally the partitions have a number and the master boot record can be accessed by the device without the 0. In my case there was /dev/sda, /dev/sda0 and /dev/sda1 available. If you were to perform the same dd command against those other partitions you would see the individual partitions boot sector rather than the master boot record.

I then transferred the MBR off using a USB flash disk since I hadn’t plugged a network cable in and fired it up in ultraedit. The type of the partition matched exactly what the article suggested it would be so I followed the instructions, changed it and copied it back. When I fired up Windows again everything was back to normal.

I had a similar thing happen about 5 years ago where the type got changed and I still haven’t figured out what causes it. Does anybody know? Back then I didn’t know Linux so well and I created a util to run from a DOS boot disk using assembler. The standard Int 13 calls I grew up with didn’t work for the big hard disks (all 10Gb) and I had to use some extended functions but I got the same basic effect.